You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
40 KiB

1 year ago
{"version":3,"file":"random.module.js","sources":["../src/rng.ts","../src/generators/function.ts","../src/rng-factory.ts","../src/distributions/uniform.ts","../src/validation.ts","../src/distributions/uniform-int.ts","../src/distributions/uniform-boolean.ts","../src/distributions/normal.ts","../src/distributions/log-normal.ts","../src/distributions/bernoulli.ts","../src/distributions/binomial.ts","../src/distributions/geometric.ts","../src/distributions/poisson.ts","../src/distributions/exponential.ts","../src/distributions/irwin-hall.ts","../src/distributions/bates.ts","../src/distributions/pareto.ts","../src/generators/math-random.ts","../src/random.ts"],"sourcesContent":["export type SeedFn = () => number\nexport type SeedType = number | string | SeedFn | RNG\n\nexport default abstract class RNG {\n abstract get name(): string\n\n abstract next(): number\n\n abstract seed(_seed?: SeedType, _opts?: Record<string, unknown>): void\n\n abstract clone(_seed?: SeedType, _opts?: Record<string, unknown>): RNG\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n _seed(seed: number, _opts?: Record<string, unknown>) {\n // TODO: add entropy and stuff\n\n if (seed === (seed || 0)) {\n return seed\n } else {\n const strSeed = '' + seed\n let s = 0\n\n for (let k = 0; k < strSeed.length; ++k) {\n s ^= strSeed.charCodeAt(k) | 0\n }\n\n return s\n }\n }\n}\n","import RNG, { SeedFn } from '../rng'\n\nexport default class RNGFunction extends RNG {\n _rng: SeedFn\n\n constructor(thunk: SeedFn, opts?: Record<string, unknown>) {\n super()\n\n this.seed(thunk, opts)\n }\n\n get name() {\n return 'function'\n }\n\n next() {\n return this._rng()\n }\n\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n seed(thunk: SeedFn, _opts?: Record<string, unknown>) {\n this._rng = thunk\n }\n\n clone(_: undefined, opts: Record<string, unknown>) {\n return new RNGFunction(this._rng, opts)\n }\n}\n","import seedrandom from 'seedrandom'\n\nimport RNG from './rng'\nimport RNGFunction from './generators/function'\n\n/**\n * Construct an RNG with variable inputs. Used in calls to Random constructor\n * @param {...*} args - Distribution-specific arguments\n * @return RNG\n *\n * @example\n * new Random(RNGFactory(...args))\n */\nexport default <T extends any[]>(...args: T) => {\n const [arg0 = 'default'] = args\n\n switch (typeof arg0) {\n case 'object':\n if (arg0 instanceof RNG) {\n return arg0\n }\n break\n\n case 'function':\n return new RNGFunction(arg0)\n\n case 'number':\n case 'string':\n default:\n return new RNGFunction(seedrandom(...args))\n }\n\n throw new Error(`invalid RNG \"${arg0}\"`)\n}\n","import { Random } from '../random'\n\nexport default (random: Random, min = 0, max = 1) => {\n return () => {\n return random.next() * (max - min) + min\n }\n}\n","export function numberValidator(num: number) {\n return new NumberValidator(num)\n}\n\nexport class NumberValidator {\n private n: number\n constructor(num: number) {\n this.n = num\n }\n\n public isInt = (): this => {\n if (Number.isInteger(this.n)) {\n return this\n }\n throw new Error(`Expected number to be an integer, got ${this.n}`)\n }\n\n public isPositive = (): this => {\n if (this.n > 0) {\n return this\n }\n throw new Error(`Expected number to be positive, got ${this.n}`)\n }\n\n public lessThan = (v: number): this => {\n if (this.n < v) {\n return this\n }\n throw new Error(`Expected number to be less than ${v}, got ${this.n}`)\n }\n\n public greaterThanOrEqual = (v: number): this => {\n if (this.n >= v) {\n return this\n }\n throw new Error(\n `Expected number to be greater than or equal to ${v}, got ${this.n}`\n )\n }\n\n public greaterThan = (v: number): this => {\n if (this.n > v) {\n return this\n }\n throw new Error(`Expected number to be greater than ${v}, got ${this.n}`)\n }\n}\n","import { Random } from '../random