idk anymore

master
max 2 years ago
parent 8b0ed2c36f
commit 4164a9f836

@ -0,0 +1,2 @@
{
}

@ -13,16 +13,26 @@ const masto = await login({
console.log("selfcarebot starting...");
const M = await masto.v1.statuses.create ({
status: 'Testing; coming soon! ๐ŸŒธ',
const data1 = fspkg.readFile('dataset1.json', 'utf8', (error, data) => {
if (error){
console.log(error);
return;
}
console.log(JSON.parse(data));
})
const status = await masto.v1.statuses.create ({
status: `${data1} selfcare! ๐ŸŒธ`,
visibility: 'public',
});
M.post('statuses', (error, data) => {
console.log('masto.v1.statuses', 'utf8', (error, data) => {
if (error) {
console.error(error);
} else {
fs.writeFileSync('data.json', JSON.stringify(data, null, 2));
fspkg.writeFileSync('data.json',JSON.stringify(data, null, 2));
console.log(data);
}
}

@ -0,0 +1,34 @@
import * as dotenv from 'dotenv';
dotenv.config();
import { login } from 'masto';
import expresspkg from 'express';
const { jsonContent } = expresspkg;
import * as fspkg from 'fs';
const { fs } = fspkg;
console.log("selfcarebot is starting...");
const masto = await login({
url: process.env.URL,
accessToken: process.env.ACCESS_TOKEN,
});
const jsonData = JSON.parse(fspkg.readFileSync('dataset1.json', 'utf-8', (error, data, status) => {
if (error){
console.log(error);
return;
}
console.log(JSON.parse(data));
console.log(JSON.parse(status));
}))
const stat = jsonData[stat];
var random = jsonData[stat][Math.floor(Math.random()*jsonContent[stat].length)];
const stati = await masto.statuses.create({
status: `${random} selfcare! ๐ŸŒธ`,
visibility: 'public',
});
console.log(stati.url);

@ -0,0 +1,2 @@
"type": "module",

@ -0,0 +1,10 @@
{
"status":[
"Yoga is",
"Baths are",
"Skin care routines are",
"New nail polish is",
"Meditation is",
"Smoking weed is"
]
}

44741
dotenv

File diff suppressed because it is too large Load Diff

105929
express

File diff suppressed because it is too large Load Diff

42533
masto

File diff suppressed because it is too large Load Diff

1
node_modules/.bin/tsc generated vendored

@ -0,0 +1 @@
../typescript/bin/tsc

1
node_modules/.bin/tsserver generated vendored

@ -0,0 +1 @@
../typescript/bin/tsserver

33
node_modules/.package-lock.json generated vendored

@ -725,6 +725,17 @@
"url": "https://github.com/sponsors/ljharb"
}
},
"node_modules/random": {
"version": "4.1.0",
"resolved": "https://registry.npmjs.org/random/-/random-4.1.0.tgz",
"integrity": "sha512-6Ajb7XmMSE9EFAMGC3kg9mvE7fGlBip25mYYuSMzw/uUSrmGilvZo2qwX3RnTRjwXkwkS+4swse9otZ92VjAtQ==",
"dependencies": {
"seedrandom": "^3.0.5"
},
"engines": {
"node": ">=14"
}
},
"node_modules/range-parser": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/range-parser/-/range-parser-1.2.1.tgz",
@ -747,6 +758,11 @@
"node": ">= 0.8"
}
},
"node_modules/rl": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/rl/-/rl-0.0.1.tgz",
"integrity": "sha512-7o+240rp1NZJa/AZeGXOued16m3iERog/Ivay4KLa6D5QGxFmoAEi2IdkH79mAqmvUo5hFILJm/l1kGOcqOTUQ=="
},
"node_modules/safe-buffer": {
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
@ -771,6 +787,11 @@
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
},
"node_modules/seedrandom": {
"version": "3.0.5",
"resolved": "https://registry.npmjs.org/seedrandom/-/seedrandom-3.0.5.tgz",
"integrity": "sha512-8OwmbklUNzwezjGInmZ+2clQmExQPvomqjL7LFqOYqtmuxRgQYqOD3mHaU+MvZn5FLUeVxVfQjwLZW/n/JFuqg=="
},
"node_modules/semver": {
"version": "7.3.8",
"resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz",
@ -902,6 +923,18 @@
"node": ">= 0.6"
}
},
"node_modules/typescript": {
"version": "5.0.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.3.tgz",
"integrity": "sha512-xv8mOEDnigb/tN9PSMTwSEqAnUvkoXMQlicOb0IUVDBSQCgBSaAAROUZYy2IcUy5qU6XajK5jjjO7TMWqBTKZA==",
"bin": {
"tsc": "bin/tsc",
"tsserver": "bin/tsserver"
},
"engines": {
"node": ">=12.20"
}
},
"node_modules/unpipe": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/unpipe/-/unpipe-1.0.0.tgz",

@ -0,0 +1,3 @@
import { Random } from '../random';
declare const _default: (random: Random, n?: number) => () => number;
export default _default;

@ -0,0 +1,3 @@
import { Random } from '../random';
declare const _default: (random: Random, p?: number) => () => number;
export default _default;

@ -0,0 +1,3 @@
import { Random } from '../random';
declare const _default: (random: Random, n?: number, p?: number) => () => number;
export default _default;

@ -0,0 +1,3 @@
import { Random } from '../random';
declare const _default: (random: Random, lambda?: number) => () => number;
export default _default;

@ -0,0 +1,3 @@
import { Random } from '../random';
declare const _default: (random: Random, p?: number) => () => number;
export default _default;

@ -0,0 +1,3 @@
import { Random } from '../random';
declare const _default: (random: Random, n?: number) => () => number;
export default _default;

@ -0,0 +1,3 @@
import { Random } from '../random';
declare const _default: (random: Random, mu?: number, sigma?: number) => () => number;
export default _default;

@ -0,0 +1,3 @@
import { Random } from '../random';
declare const _default: (random: Random, mu?: number, sigma?: number) => () => number;
export default _default;

@ -0,0 +1,3 @@
import { Random } from '../random';
declare const _default: (random: Random, alpha?: number) => () => number;
export default _default;

@ -0,0 +1,3 @@
import { Random } from '../random';
declare const _default: (random: Random, lambda?: number) => () => number;
export default _default;

@ -0,0 +1,3 @@
import { Random } from '../random';
declare const _default: (random: Random) => () => boolean;
export default _default;

@ -0,0 +1,3 @@
import { Random } from '../random';
declare const _default: (random: Random, min?: number, max?: number) => () => number;
export default _default;

@ -0,0 +1,3 @@
import { Random } from '../random';
declare const _default: (random: Random, min?: number, max?: number) => () => number;
export default _default;

@ -0,0 +1,9 @@
import RNG, { SeedFn } from '../rng';
export default class RNGFunction extends RNG {
_rng: SeedFn;
constructor(thunk: SeedFn, opts?: Record<string, unknown>);
get name(): string;
next(): number;
seed(thunk: SeedFn, _opts?: Record<string, unknown>): void;
clone(_: undefined, opts: Record<string, unknown>): RNGFunction;
}

@ -0,0 +1,7 @@
import RNG from '../rng';
export default class RNGMathRandom extends RNG {
get name(): string;
next(): number;
seed(_seed: unknown, _opts: Record<string, unknown>): void;
clone(): RNGMathRandom;
}

@ -0,0 +1,12 @@
import RNG from '../rng';
export default class RNGXOR128 extends RNG {
x: number;
y: number;
z: number;
w: number;
constructor(seed: number, opts?: Record<string, unknown>);
get name(): string;
next(): number;
seed(seed: number, opts?: Record<string, unknown>): void;
clone(seed: number, opts: Record<string, unknown>): RNGXOR128;
}

@ -0,0 +1,3 @@
import random from './random';
export * from './random';
export default random;

@ -0,0 +1,267 @@
import RNG from './rng';
import RNGFactory from './rng-factory';
/**
* Distribution function
*/
interface IDistFn<R> {
(random: Random, ...argv: any): R;
}
/**
* Distribution
*/
interface IDist<R> {
(): R;
}
/**
* Keyed cache entry
*/
interface ICacheEntry<T> {
key: string;
distribution: () => T;
}
export { RNG, RNGFactory };
/**
* Seedable random number generator supporting many common distributions.
*
* Defaults to Math.random as its underlying pseudorandom number generator.
*
* @name Random
* @class
*
* @param {RNG|function} [rng=Math.random] - Underlying pseudorandom number generator.
*/
export declare class Random {
protected _rng: RNG;
protected _patch: typeof Math.random | undefined;
protected _cache: {
[k: string]: ICacheEntry<any>;
};
constructor(rng?: RNG);
/**
* @member {RNG} Underlying pseudo-random number generator
*/
get rng(): RNG;
/**
* Creates a new `Random` instance, optionally specifying parameters to
* set a new seed.
*
* @see RNG.clone
*
* @param {string} [seed] - Optional seed for new RNG.
* @param {object} [opts] - Optional config for new RNG options.
* @return {Random}
*/
clone<T>(...args: [T]): Random;
/**
* Sets the underlying pseudorandom number generator used via
* either an instance of `seedrandom`, a custom instance of RNG
* (for PRNG plugins), or a string specifying the PRNG to use
* along with an optional `seed` and `opts` to initialize the
* RNG.
*
* @example
* import random from 'random'
*
* random.use('example_seedrandom_string')
* // or
* random.use(seedrandom('kittens'))
* // or
* random.use(Math.random)
*
* @param {...*} args
*/
use(...args: [RNG]): void;
/**
* Patches `Math.random` with this Random instance's PRNG.
*/
patch(): void;
/**
* Restores a previously patched `Math.random` to its original value.
*/
unpatch(): void;
/**
* Convenience wrapper around `this.rng.next()`
*
* Returns a floating point number in [0, 1).
*
* @return {number}
*/
next: () => number;
/**
* Samples a uniform random floating point number, optionally specifying
* lower and upper bounds.
*
* Convence wrapper around `random.uniform()`
*
* @param {number} [min=0] - Lower bound (float, inclusive)
* @param {number} [max=1] - Upper bound (float, exclusive)
* @return {number}
*/
float: (min?: number, max?: number) => number;
/**
* Samples a uniform random integer, optionally specifying lower and upper
* bounds.
*
* Convence wrapper around `random.uniformInt()`
*
* @param {number} [min=0] - Lower bound (integer, inclusive)
* @param {number} [max=1] - Upper bound (integer, inclusive)
* @return {number}
*/
int: (min?: number, max?: number) => number;
/**
* Samples a uniform random integer, optionally specifying lower and upper
* bounds.
*
* Convence wrapper around `random.uniformInt()`
*
* @alias `random.int`
*
* @param {number} [min=0] - Lower bound (integer, inclusive)
* @param {number} [max=1] - Upper bound (integer, inclusive)
* @return {number}
*/
integer: (min?: number, max?: number) => number;
/**
* Samples a uniform random boolean value.
*
* Convence wrapper around `random.uniformBoolean()`
*
* @alias `random.boolean`
*
* @return {boolean}
*/
bool: () => boolean;
/**
* Samples a uniform random boolean value.
*
* Convence wrapper around `random.uniformBoolean()`
*
* @return {boolean}
*/
boolean: () => boolean;
/**
* Returns an item chosen uniformly at trandom from the given array.
*
* Convence wrapper around `random.uniformInt()`
*
* @param {Array<T>} [array] - Lower bound (integer, inclusive)
* @return {T | undefined}
*/
choice<T>(array: Array<T>): T | undefined;
/**
* Generates a [Continuous uniform distribution](https://en.wikipedia.org/wiki/Uniform_distribution_(continuous)).
*
* @param {number} [min=0] - Lower bound (float, inclusive)
* @param {number} [max=1] - Upper bound (float, exclusive)
* @return {function}
*/
uniform: (min?: number, max?: number) => IDist<number>;
/**
* Generates a [Discrete uniform distribution](https://en.wikipedia.org/wiki/Discrete_uniform_distribution).
*
* @param {number} [min=0] - Lower bound (integer, inclusive)
* @param {number} [max=1] - Upper bound (integer, inclusive)
* @return {function}
*/
uniformInt: (min?: number, max?: number) => IDist<number>;
/**
* Generates a [Discrete uniform distribution](https://en.wikipedia.org/wiki/Discrete_uniform_distribution),
* with two possible outcomes, `true` or `false.
*
* This method is analogous to flipping a coin.
*
* @return {function}
*/
uniformBoolean: () => IDist<boolean>;
/**
* Generates a [Normal distribution](https://en.wikipedia.org/wiki/Normal_distribution).
*
* @param {number} [mu=0] - Mean
* @param {number} [sigma=1] - Standard deviation
* @return {function}
*/
normal: (mu?: number, sigma?: number) => () => number;
/**
* Generates a [Log-normal distribution](https://en.wikipedia.org/wiki/Log-normal_distribution).
*
* @param {number} [mu=0] - Mean of underlying normal distribution
* @param {number} [sigma=1] - Standard deviation of underlying normal distribution
* @return {function}
*/
logNormal: (mu?: number, sigma?: number) => () => number;
/**
* Generates a [Bernoulli distribution](https://en.wikipedia.org/wiki/Bernoulli_distribution).
*
* @param {number} [p=0.5] - Success probability of each trial.
* @return {function}
*/
bernoulli: (p?: number) => () => number;
/**
* Generates a [Binomial distribution](https://en.wikipedia.org/wiki/Binomial_distribution).
*
* @param {number} [n=1] - Number of trials.
* @param {number} [p=0.5] - Success probability of each trial.
* @return {function}
*/
binomial: (n?: number, p?: number) => () => number;
/**
* Generates a [Geometric distribution](https://en.wikipedia.org/wiki/Geometric_distribution).
*
* @param {number} [p=0.5] - Success probability of each trial.
* @return {function}
*/
geometric: (p?: number) => () => number;
/**
* Generates a [Poisson distribution](https://en.wikipedia.org/wiki/Poisson_distribution).
*
* @param {number} [lambda=1] - Mean (lambda > 0)
* @return {function}
*/
poisson: (lambda?: number) => () => number;
/**
* Generates an [Exponential distribution](https://en.wikipedia.org/wiki/Exponential_distribution).
*
* @param {number} [lambda=1] - Inverse mean (lambda > 0)
* @return {function}
*/
exponential: (lambda?: number) => () => number;
/**
* Generates an [Irwin Hall distribution](https://en.wikipedia.org/wiki/Irwin%E2%80%93Hall_distribution).
*
* @param {number} [n=1] - Number of uniform samples to sum (n >= 0)
* @return {function}
*/
irwinHall: (n?: number) => () => number;
/**
* Generates a [Bates distribution](https://en.wikipedia.org/wiki/Bates_distribution).
*
* @param {number} [n=1] - Number of uniform samples to average (n >= 1)
* @return {function}
*/
bates: (n?: number) => () => number;
/**
* Generates a [Pareto distribution](https://en.wikipedia.org/wiki/Pareto_distribution).
*
* @param {number} [alpha=1] - Alpha
* @return {function}
*/
pareto: (alpha?: number) => () => number;
/**
* Memoizes distributions to ensure they're only created when necessary.
*
* Returns a thunk which that returns independent, identically distributed
* samples from the specified distribution.
*
* @private
*
* @param {string} label - Name of distribution
* @param {function} getter - Function which generates a new distribution
* @param {...*} args - Distribution-specific arguments
*
* @return {function}
*/
_memoize<T>(label: string, getter: IDistFn<any>, ...args: any[]): IDist<T>;
}
declare const _default: Random;
export default _default;

@ -0,0 +1,638 @@
import seedrandom from 'seedrandom';
function _defineProperties(target, props) {
for (var i = 0; i < props.length; i++) {
var descriptor = props[i];
descriptor.enumerable = descriptor.enumerable || false;
descriptor.configurable = true;
if ("value" in descriptor) descriptor.writable = true;
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
}
}
function _createClass(Constructor, protoProps, staticProps) {
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
if (staticProps) _defineProperties(Constructor, staticProps);
Object.defineProperty(Constructor, "prototype", {
writable: false
});
return Constructor;
}
function _inheritsLoose(subClass, superClass) {
subClass.prototype = Object.create(superClass.prototype);
subClass.prototype.constructor = subClass;
_setPrototypeOf(subClass, superClass);
}
function _setPrototypeOf(o, p) {
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
o.__proto__ = p;
return o;
};
return _setPrototypeOf(o, p);
}
function _toPrimitive(input, hint) {
if (typeof input !== "object" || input === null) return input;
var prim = input[Symbol.toPrimitive];
if (prim !== undefined) {
var res = prim.call(input, hint || "default");
if (typeof res !== "object") return res;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return (hint === "string" ? String : Number)(input);
}
function _toPropertyKey(arg) {
var key = _toPrimitive(arg, "string");
return typeof key === "symbol" ? key : String(key);
}
var RNG = /*#__PURE__*/function () {
function RNG() {}
var _proto = RNG.prototype;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_proto._seed = function _seed(seed, _opts) {
// TODO: add entropy and stuff
if (seed === (seed || 0)) {
return seed;
} else {
var strSeed = '' + seed;
var s = 0;
for (var k = 0; k < strSeed.length; ++k) {
s ^= strSeed.charCodeAt(k) | 0;
}
return s;
}
};
return RNG;
}();
var RNGFunction = /*#__PURE__*/function (_RNG) {
_inheritsLoose(RNGFunction, _RNG);
function RNGFunction(thunk, opts) {
var _this;
_this = _RNG.call(this) || this;
_this._rng = void 0;
_this.seed(thunk, opts);
return _this;
}
var _proto = RNGFunction.prototype;
_proto.next = function next() {
return this._rng();
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
;
_proto.seed = function seed(thunk, _opts) {
this._rng = thunk;
};
_proto.clone = function clone(_, opts) {
return new RNGFunction(this._rng, opts);
};
_createClass(RNGFunction, [{
key: "name",
get: function get() {
return 'function';
}
}]);
return RNGFunction;
}(RNG);
/**
* Construct an RNG with variable inputs. Used in calls to Random constructor
* @param {...*} args - Distribution-specific arguments
* @return RNG
*
* @example
* new Random(RNGFactory(...args))
*/
var RNGFactory = (function () {
var args = [].slice.call(arguments);
var _args = args,
_args$ = _args[0],
arg0 = _args$ === void 0 ? 'default' : _args$;
switch (typeof arg0) {
case 'object':
if (arg0 instanceof RNG) {
return arg0;
}
break;
case 'function':
return new RNGFunction(arg0);
case 'number':
case 'string':
default:
return new RNGFunction(seedrandom.apply(void 0, args));
}
throw new Error("invalid RNG \"" + arg0 + "\"");
});
var uniform = (function (random, min, max) {
if (min === void 0) {
min = 0;
}
if (max === void 0) {
max = 1;
}
return function () {
return random.next() * (max - min) + min;
};
});
function numberValidator(num) {
return new NumberValidator(num);
}
var NumberValidator = function NumberValidator(num) {
var _this = this;
this.n = void 0;
this.isInt = function () {
if (Number.isInteger(_this.n)) {
return _this;
}
throw new Error("Expected number to be an integer, got " + _this.n);
};
this.isPositive = function () {
if (_this.n > 0) {
return _this;
}
throw new Error("Expected number to be positive, got " + _this.n);
};
this.lessThan = function (v) {
if (_this.n < v) {
return _this;
}
throw new Error("Expected number to be less than " + v + ", got " + _this.n);
};
this.greaterThanOrEqual = function (v) {
if (_this.n >= v) {
return _this;
}
throw new Error("Expected number to be greater than or equal to " + v + ", got " + _this.n);
};
this.greaterThan = function (v) {
if (_this.n > v) {
return _this;
}
throw new Error("Expected number to be greater than " + v + ", got " + _this.n);
};
this.n = num;
};
var uniformInt = (function (random, min, max) {
if (min === void 0) {
min = 0;
}
if (max === void 0) {
max = 1;
}
if (max === undefined) {
max = min === undefined ? 1 : min;
min = 0;
}
numberValidator(min).isInt();
numberValidator(max).isInt();
return function () {
return Math.floor(random.next() * (max - min + 1) + min);
};
});
var uniformBoolean = (function (random) {
return function () {
return random.next() >= 0.5;
};
});
var normal = (function (random, mu, sigma) {
if (mu === void 0) {
mu = 0;
}
if (sigma === void 0) {
sigma = 1;
}
return function () {
var x, y, r;
do {
x = random.next() * 2 - 1;
y = random.next() * 2 - 1;
r = x * x + y * y;
} while (!r || r > 1);
return mu + sigma * y * Math.sqrt(-2 * Math.log(r) / r);
};
});
var logNormal = (function (random, mu, sigma) {
if (mu === void 0) {
mu = 0;
}
if (sigma === void 0) {
sigma = 1;
}
var normal = random.normal(mu, sigma);
return function () {
return Math.exp(normal());
};
});
var bernoulli = (function (random, p) {
if (p === void 0) {
p = 0.5;
}
numberValidator(p).greaterThanOrEqual(0).lessThan(1);
return function () {
return Math.floor(random.next() + p);
};
});
var binomial = (function (random, n, p) {
if (n === void 0) {
n = 1;
}
if (p === void 0) {
p = 0.5;
}
numberValidator(n).isInt().isPositive();
numberValidator(p).greaterThanOrEqual(0).lessThan(1);
return function () {
var i = 0;
var x = 0;
while (i++ < n) {
if (random.next() < p) {
x++;
}
}
return x;
};
});
var geometric = (function (random, p) {
if (p === void 0) {
p = 0.5;
}
numberValidator(p).greaterThan(0).lessThan(1);
var invLogP = 1.0 / Math.log(1.0 - p);
return function () {
return Math.floor(1 + Math.log(random.next()) * invLogP);
};
});
var logFactorialTable = [0.0, 0.0, 0.69314718055994529, 1.791759469228055, 3.1780538303479458, 4.7874917427820458, 6.5792512120101012, 8.5251613610654147, 10.604602902745251, 12.801827480081469];
var logFactorial = function logFactorial(k) {
return logFactorialTable[k];
};
var logSqrt2PI = 0.91893853320467267;
var poisson = (function (random, lambda) {
if (lambda === void 0) {
lambda = 1;
}
numberValidator(lambda).isPositive();
if (lambda < 10) {
// inversion method
var expMean = Math.exp(-lambda);
return function () {
var p = expMean;
var x = 0;
var u = random.next();
while (u > p) {
u = u - p;
p = lambda * p / ++x;
}
return x;
};
} else {
// generative method
var smu = Math.sqrt(lambda);
var b = 0.931 + 2.53 * smu;
var a = -0.059 + 0.02483 * b;
var invAlpha = 1.1239 + 1.1328 / (b - 3.4);
var vR = 0.9277 - 3.6224 / (b - 2);
return function () {
while (true) {
var u = void 0;
var v = random.next();
if (v <= 0.86 * vR) {
u = v / vR - 0.43;
return Math.floor((2 * a / (0.5 - Math.abs(u)) + b) * u + lambda + 0.445);
}
if (v >= vR) {
u = random.next() - 0.5;
} else {
u = v / vR - 0.93;
u = (u < 0 ? -0.5 : 0.5) - u;
v = random.next() * vR;
}
var us = 0.5 - Math.abs(u);
if (us < 0.013 && v > us) {
continue;
}
var k = Math.floor((2 * a / us + b) * u + lambda + 0.445);
v = v * invAlpha / (a / (us * us) + b);
if (k >= 10) {
var t = (k + 0.5) * Math.log(lambda / k) - lambda - logSqrt2PI + k - (1 / 12.0 - (1 / 360.0 - 1 / (1260.0 * k * k)) / (k * k)) / k;
if (Math.log(v * smu) <= t) {
return k;
}
} else if (k >= 0) {
var _logFactorial;
var f = (_logFactorial = logFactorial(k)) != null ? _logFactorial : 0;
if (Math.log(v) <= k * Math.log(lambda) - lambda - f) {
return k;
}
}
}
};
}
});
var exponential = (function (random, lambda) {
if (lambda === void 0) {
lambda = 1;
}
numberValidator(lambda).isPositive();
return function () {
return -Math.log(1 - random.next()) / lambda;
};
});
var irwinHall = (function (random, n) {
if (n === void 0) {
n = 1;
}
numberValidator(n).isInt().greaterThanOrEqual(0);
return function () {
var sum = 0;
for (var i = 0; i < n; ++i) {
sum += random.next();
}
return sum;
};
});
var bates = (function (random, n) {
if (n === void 0) {
n = 1;
}
numberValidator(n).isInt().isPositive();
var irwinHall = random.irwinHall(n);
return function () {
return irwinHall() / n;
};
});
var pareto = (function (random, alpha) {
if (alpha === void 0) {
alpha = 1;
}
numberValidator(alpha).greaterThanOrEqual(0);
var invAlpha = 1.0 / alpha;
return function () {
return 1.0 / Math.pow(1.0 - random.next(), invAlpha);
};
});
var RNGMathRandom = /*#__PURE__*/function (_RNG) {
_inheritsLoose(RNGMathRandom, _RNG);
function RNGMathRandom() {
return _RNG.apply(this, arguments) || this;
}
var _proto = RNGMathRandom.prototype;
_proto.next = function next() {
return Math.random();
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
;
_proto.seed = function seed(_seed, _opts) {
// intentionally empty
};
_proto.clone = function clone() {
return new RNGMathRandom();
};
_createClass(RNGMathRandom, [{
key: "name",
get: function get() {
return 'default';
}
}]);
return RNGMathRandom;
}(RNG);
/**
* Seedable random number generator supporting many common distributions.
*
* Defaults to Math.random as its underlying pseudorandom number generator.
*
* @name Random
* @class
*
* @param {RNG|function} [rng=Math.random] - Underlying pseudorandom number generator.
*/
var Random = /*#__PURE__*/function () {
function Random(rng) {
var _this = this;
this._rng = void 0;
this._patch = void 0;
this._cache = {};
this.next = function () {
return _this._rng.next();
};
this["float"] = function (min, max) {
return _this.uniform(min, max)();
};
this["int"] = function (min, max) {
return _this.uniformInt(min, max)();
};
this.integer = function (min, max) {
return _this.uniformInt(min, max)();
};
this.bool = function () {
return _this.uniformBoolean()();
};
this["boolean"] = function () {
return _this.uniformBoolean()();
};
this.uniform = function (min, max) {
return _this._memoize('uniform', uniform, min, max);
};
this.uniformInt = function (min, max) {
return _this._memoize('uniformInt', uniformInt, min, max);
};
this.uniformBoolean = function () {
return _this._memoize('uniformBoolean', uniformBoolean);
};
this.normal = function (mu, sigma) {
return normal(_this, mu, sigma);
};
this.logNormal = function (mu, sigma) {
return logNormal(_this, mu, sigma);
};
this.bernoulli = function (p) {
return bernoulli(_this, p);
};
this.binomial = function (n, p) {
return binomial(_this, n, p);
};
this.geometric = function (p) {
return geometric(_this, p);
};
this.poisson = function (lambda) {
return poisson(_this, lambda);
};
this.exponential = function (lambda) {
return exponential(_this, lambda);
};
this.irwinHall = function (n) {
return irwinHall(_this, n);
};
this.bates = function (n) {
return bates(_this, n);
};
this.pareto = function (alpha) {
return pareto(_this, alpha);
};
if (rng && rng instanceof RNG) {
this.use(rng);
} else {
this.use(new RNGMathRandom());
}
this._cache = {};
}
/**
* @member {RNG} Underlying pseudo-random number generator
*/
var _proto = Random.prototype;
/**
* Creates a new `Random` instance, optionally specifying parameters to
* set a new seed.
*
* @see RNG.clone
*
* @param {string} [seed] - Optional seed for new RNG.
* @param {object} [opts] - Optional config for new RNG options.
* @return {Random}
*/
_proto.clone = function clone() {
var args = [].slice.call(arguments);
if (args.length) {
return new Random(RNGFactory.apply(void 0, args));
} else {
return new Random(this.rng.clone());
}
}
/**
* Sets the underlying pseudorandom number generator used via
* either an instance of `seedrandom`, a custom instance of RNG
* (for PRNG plugins), or a string specifying the PRNG to use
* along with an optional `seed` and `opts` to initialize the
* RNG.
*
* @example
* import random from 'random'
*
* random.use('example_seedrandom_string')
* // or
* random.use(seedrandom('kittens'))
* // or
* random.use(Math.random)
*
* @param {...*} args
*/;
_proto.use = function use() {
this._rng = RNGFactory.apply(void 0, [].slice.call(arguments));
}
/**
* Patches `Math.random` with this Random instance's PRNG.
*/;
_proto.patch = function patch() {
if (this._patch) {
throw new Error('Math.random already patched');
}
this._patch = Math.random;
Math.random = this.uniform();
}
/**
* Restores a previously patched `Math.random` to its original value.
*/;
_proto.unpatch = function unpatch() {
if (this._patch) {
Math.random = this._patch;
delete this._patch;
}
}
// --------------------------------------------------------------------------
// Uniform utility functions
// --------------------------------------------------------------------------
/**
* Convenience wrapper around `this.rng.next()`
*
* Returns a floating point number in [0, 1).
*
* @return {number}
*/;
/**
* Returns an item chosen uniformly at trandom from the given array.
*
* Convence wrapper around `random.uniformInt()`
*
* @param {Array<T>} [array] - Lower bound (integer, inclusive)
* @return {T | undefined}
*/
_proto.choice = function choice(array) {
if (!Array.isArray(array)) {
throw new Error("Random.choice expected input to be an array, got " + typeof array);
}
var length = array == null ? void 0 : array.length;
if (length > 0) {
var index = this.uniformInt(0, length - 1)();
return array[index];
} else {
return undefined;
}
}
// --------------------------------------------------------------------------
// Uniform distributions
// --------------------------------------------------------------------------
/**
* Generates a [Continuous uniform distribution](https://en.wikipedia.org/wiki/Uniform_distribution_(continuous)).
*
* @param {number} [min=0] - Lower bound (float, inclusive)
* @param {number} [max=1] - Upper bound (float, exclusive)
* @return {function}
*/;
// --------------------------------------------------------------------------
// Internal
// --------------------------------------------------------------------------
/**
* Memoizes distributions to ensure they're only created when necessary.
*
* Returns a thunk which that returns independent, identically distributed
* samples from the specified distribution.
*
* @private
*
* @param {string} label - Name of distribution
* @param {function} getter - Function which generates a new distribution
* @param {...*} args - Distribution-specific arguments
*
* @return {function}
*/
_proto._memoize = function _memoize(label, getter) {
var args = [].slice.call(arguments, 2);
var key = "" + args.join(';');
var value = this._cache[label];
if (value === undefined || value.key !== key) {
value = {
key: key,
distribution: getter.apply(void 0, [this].concat(args))
};
this._cache[label] = value;
}
return value.distribution;
};
_createClass(Random, [{
key: "rng",
get: function get() {
return this._rng;
}
}]);
return Random;
}();
// defaults to Math.random as its RNG
var random = new Random();
export { RNG, RNGFactory, Random, random as default };
//# sourceMappingURL=random.module.js.map

File diff suppressed because one or more lines are too long

@ -0,0 +1,11 @@
import RNG from './rng';
/**
* Construct an RNG with variable inputs. Used in calls to Random constructor
* @param {...*} args - Distribution-specific arguments
* @return RNG
*
* @example
* new Random(RNGFactory(...args))
*/
declare const _default: <T extends any[]>(...args: T) => RNG;
export default _default;

@ -0,0 +1,9 @@
export type SeedFn = () => number;
export type SeedType = number | string | SeedFn | RNG;
export default abstract class RNG {
abstract get name(): string;
abstract next(): number;
abstract seed(_seed?: SeedType, _opts?: Record<string, unknown>): void;
abstract clone(_seed?: SeedType, _opts?: Record<string, unknown>): RNG;
_seed(seed: number, _opts?: Record<string, unknown>): number;
}

@ -0,0 +1,10 @@
export declare function numberValidator(num: number): NumberValidator;
export declare class NumberValidator {
private n;
constructor(num: number);
isInt: () => this;
isPositive: () => this;
lessThan: (v: number) => this;
greaterThanOrEqual: (v: number) => this;
greaterThan: (v: number) => this;
}

21
node_modules/random/license generated vendored

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2022 Travis Fischer
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

89
node_modules/random/package.json generated vendored

@ -0,0 +1,89 @@
{
"name": "random",
"version": "4.1.0",
"description": "Seedable random number generator supporting many common distributions.",
"repository": "transitive-bullshit/random",
"author": "Travis Fischer <travis@transitivebullsh.it>",
"type": "module",
"exports": {
"import": "./dist/random.module.js",
"types": "./dist/index.d.ts",
"default": "./dist/random.module.js"
},
"files": [
"dist"
],
"source": "./src/index.ts",
"module": "./dist/random.module.js",
"types": "./dist/index.d.ts",
"sideEffects": false,
"license": "MIT",
"engines": {
"node": ">=14"
},
"scripts": {
"start": "run-s build:watch",
"build": "microbundle -f esm --no-compress",
"build:watch": "microbundle -f esm --no-compress --watch",
"prebuild": "run-s clean",
"prebuild:watch": "run-s clean",
"clean": "del dist",
"prepublishOnly": "run-s build",
"docs": "update-markdown-jsdoc -f dist/random.module.js --shallow",
"pretest": "run-s build",
"test": "run-s test:*",
"test:unit": "ava -v",
"test:prettier": "prettier '**/*.{js,jsx,ts,tsx}' --check",
"test:lint": "eslint ."
},
"keywords": [
"random",
"number",
"generator",
"rng",
"prng",
"stats",
"d3-random",
"seedrandom",
"distribution",
"pseudorandom",
"uniform",
"normal",
"gaussian",
"lognormal",
"poisson",
"exponential",
"irwinhall",
"bates"
],
"dependencies": {
"seedrandom": "^3.0.5"
},
"devDependencies": {
"@ava/typescript": "^3.0.1",
"@esbuild-kit/esm-loader": "^2.5.0",
"@types/node": "^18.11.9",
"@types/seedrandom": "^3.0.2",
"@typescript-eslint/eslint-plugin": "^5.42.1",
"@typescript-eslint/parser": "^5.42.1",
"ava": "^5.0.1",
"del-cli": "^5.0.0",
"eslint": "^8.27.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-prettier": "^4.2.1",
"microbundle": "^0.15.1",
"npm-run-all": "^4.1.5",
"prettier": "^2.7.1",
"typescript": "^4.8.4",
"update-markdown-jsdoc": "^1.0.11"
},
"ava": {
"extensions": {
"ts": "module"
},
"nodeArguments": [
"--loader=@esbuild-kit/esm-loader"
]
}
}

523
node_modules/random/readme.md generated vendored

@ -0,0 +1,523 @@
# random <!-- omit in toc -->
> Seedable random number generator supporting many common distributions.
[![NPM](https://img.shields.io/npm/v/random.svg)](https://www.npmjs.com/package/random) [![Build Status](https://github.com/transitive-bullshit/random/actions/workflows/test.yml/badge.svg)](https://github.com/transitive-bullshit/random/actions/workflows/test.yml) [![Prettier Code Formatting](https://img.shields.io/badge/code_style-prettier-brightgreen.svg)](https://prettier.io)
Welcome to the most **random** module on npm! ๐Ÿ˜œ
## Highlights <!-- omit in toc -->
- Simple API (_make easy things easy and hard things possible_)
- TypeScript supported!
- Seedable based on entropy or user input
- Plugin support for different pseudo random number generators (PRNGs)
- Sample from many common distributions
- uniform, normal, poisson, bernoulli, etc
- Validates all user input via [ow](https://github.com/sindresorhus/ow)
- Integrates with [seedrandom](https://github.com/davidbau/seedrandom)
- Supports node >= 14 and browser
## Install <!-- omit in toc -->
```bash
npm install --save random
# or
yarn add random
# or
pnpm add random
```
Note: this package uses ESM and no longer provides a CommonJS export. See [here](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c) for more info on how to use ESM modules.
## Usage <!-- omit in toc -->
```ts
import random from 'random'
// quick uniform shortcuts
random.float((min = 0), (max = 1)) // uniform float in [ min, max )
random.int((min = 0), (max = 1)) // uniform integer in [ min, max ]
random.boolean() // true or false
// uniform distribution
random.uniform((min = 0), (max = 1)) // () => [ min, max )
random.uniformInt((min = 0), (max = 1)) // () => [ min, max ]
random.uniformBoolean() // () => [ false, true ]
// normal distribution
random.normal((mu = 0), (sigma = 1))
random.logNormal((mu = 0), (sigma = 1))
// bernoulli distribution
random.bernoulli((p = 0.5))
random