@mark1russell7/rigor-generators 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -33,7 +33,43 @@ for (const seed of seedsFrom(process.env.SEED, [1, 2, 3, 4, 5])) {
33
33
  }
34
34
  ```
35
35
 
36
- The package also exports the parts: `mulberry32(seed)` (the raw source), `fnv1a32(text)` (the FNV-1a hash of the UTF-8 bytes), `seedOf(seed)`, `deriveSeed(seed, label)` and `randomOf(source, seed)` (the draws over a source that you give).
36
+ The package also exports the parts: `mulberry32(seed)` (the raw source), `fnv1a32(text, options)` (the FNV-1a hash), `seedOf(seed)`, `deriveSeed(seed, label)` and `randomOf(source, seed)` (the draws over a source that you give).
37
+
38
+ ## Open families of distributions
39
+
40
+ A closed list of size names cannot grow without a change to each corpus. A `DistributionSpec` names a family and its parameters, so a corpus can name any point of the family.
41
+
42
+ | Family | Parameters | Numbers |
43
+ | --- | --- | --- |
44
+ | `lognormal` | `mu`, `sigma` | above 0, with a long tail |
45
+ | `pareto` | `scale`, `shape` | `scale` or more, with a heavy tail |
46
+ | `zipf` | `n`, `exponent` | the ranks from 1 to `n` |
47
+ | `beta` | `a`, `b` | from 0 to 1 |
48
+ | `mixture` | `parts`, each with a `weight` | one value of one part |
49
+ | `recorded` | `values` | one of the recorded values |
50
+
51
+ ```ts
52
+ import { random, sampler } from "@mark1russell7/rigor-generators";
53
+
54
+ const next = sampler({ family: "lognormal", mu: [1, 2], sigma: 0.5 }, random("widths"));
55
+ const widths = Array.from({ length: 100 }, () => next());
56
+ ```
57
+
58
+ A parameter is a number or a range `[min, max]`. `sampler` draws from a range once, so one sampler is one point of the family.
59
+
60
+ `Math.exp`, `Math.log` and `Math.pow` can give other results on another JavaScript engine. `dependsOnLibm` tells if a spec uses them. Only `recorded` does not, so write the numbers of the other families into a corpus when a corpus must match on each platform.
61
+
62
+ ## The input of `fnv1a32`
63
+
64
+ The option `input` of `fnv1a32` selects the units that the hash reads. Use it to replace a local copy of FNV-1a with the same hashes.
65
+
66
+ | `input` | The hash reads | A copy with this form |
67
+ | --- | --- | --- |
68
+ | `"utf8"` (the default) | The bytes of `TextEncoder`. A lone surrogate becomes the bytes of U+FFFD. | `new TextEncoder().encode(text)` |
69
+ | `"utf16"` | Each UTF-16 code unit, one unit for each step. | `h ^= text.charCodeAt(i)` |
70
+ | `"wtf8"` | The UTF-8 bytes of each code point. A lone surrogate becomes its own 3 bytes. | A UTF-8 encoder over `for (const ch of text)` |
71
+
72
+ For a string without a lone surrogate, `"utf8"` and `"wtf8"` give the same hash.
37
73
 
38
74
  ## Move from a copy of mulberry32
39
75
 
package/build/index.d.ts CHANGED
@@ -9,8 +9,18 @@
9
9
  type Source = () => number;
10
10
  /** The generator mulberry32. The seed is read as a 32-bit unsigned integer. */
11
11
  export declare function mulberry32(seed: number): Source;
12
- /** The FNV-1a hash of 32 bits of the UTF-8 bytes of a string. */
13
- export declare function fnv1a32(text: string): number;
12
+ /**
13
+ * The FNV-1a hash of 32 bits of a string. The option `input` selects the units that the hash reads:
14
+ *
15
+ * - `"utf8"` (the default): the UTF-8 bytes from `TextEncoder`. A lone surrogate becomes the bytes of U+FFFD.
16
+ * - `"utf16"`: the UTF-16 code units of the string, one unit for each step, from `charCodeAt`.
17
+ * - `"wtf8"`: the UTF-8 bytes of each code point. A lone surrogate becomes its own 3 bytes (WTF-8).
18
+ *
19
+ * For a string without a lone surrogate, `"utf8"` and `"wtf8"` give the same hash.
20
+ */
21
+ export declare function fnv1a32(text: string, options?: {
22
+ readonly input?: "utf8" | "utf16" | "wtf8";
23
+ }): number;
14
24
  /** The 32-bit seed of a number (its low 32 bits, unsigned) or of a string (its FNV-1a hash). */
15
25
  export declare function seedOf(seed: number | string): number;
16
26
  /** The seed of the stream with the name `label` under `seed`: the hash of `"<seed>:<label>"`. */
@@ -50,5 +60,44 @@ export declare function randomOf(next: Source, seed: number, source?: (seed: num
50
60
  * `process.env.SEED`), else the default seeds. An empty text gives the defaults.
51
61
  */
52
62
  export declare function seedsFrom(given: string | undefined, defaults: readonly number[]): number[];
53
- export type { Random, Source };
63
+ /** A parameter of a family: one value, or a range from `min` to `max` that `sampler` draws from once. */
64
+ type Param = number | readonly [min: number, max: number];
65
+ /** A family of distributions and its parameters. */
66
+ type DistributionSpec = {
67
+ readonly family: "lognormal";
68
+ readonly mu: Param;
69
+ readonly sigma: Param;
70
+ } | {
71
+ readonly family: "pareto";
72
+ readonly scale: Param;
73
+ readonly shape: Param;
74
+ } | {
75
+ readonly family: "zipf";
76
+ readonly n: number;
77
+ readonly exponent: Param;
78
+ } | {
79
+ readonly family: "beta";
80
+ readonly a: Param;
81
+ readonly b: Param;
82
+ } | {
83
+ readonly family: "mixture";
84
+ readonly parts: readonly {
85
+ readonly weight: number;
86
+ readonly part: DistributionSpec;
87
+ }[];
88
+ } | {
89
+ readonly family: "recorded";
90
+ readonly values: readonly number[];
91
+ };
92
+ /**
93
+ * This function gives a sampler of a family. It fixes each parameter once, so a range gives one point of the family.
94
+ * Each call of the sampler gives one number. The same seed and the same spec give the same numbers on one platform.
95
+ */
96
+ export declare function sampler(spec: DistributionSpec, r: Random): () => number;
97
+ /**
98
+ * This function tells if the numbers of a family use `Math.exp`, `Math.log` or `Math.pow`.
99
+ * The result of those functions can change between JavaScript engines. Thus such a family has the same numbers only on one platform.
100
+ */
101
+ export declare function dependsOnLibm(spec: DistributionSpec): boolean;
102
+ export type { DistributionSpec, Param, Random, Source };
54
103
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/random.ts"],"mappings":";;;;;;;;KASY;;wBAGI,WAAW,eAAe;;wBAc1B,QAAQ;;wBAOR,OAAO;;wBAOP,WAAW,cAAc;UAIxB;;WAEN;;EAET;;EAEA,IAAI,aAAa;;EAEjB,MAAM;;EAEN,MAAM,aAAa;;EAEnB,OAAO;;EAEP,KAAK,GAAG,gBAAgB,MAAM;;EAE9B,SAAS;;EAET,QAAQ,GAAG,gBAAgB,MAAM;;EAEjC,OAAO,GAAG,gBAAgB,KAAK,YAAY;;EAE3C,OAAO,eAAe;;EAEtB,KAAK,gBAAgB;;;wBAQP,OAAO,uBAAuB,UAAS,iBAAiB,SAAsB;;wBAM9E,SAAS,MAAM,QAAQ,cAAc,UAAS,iBAAiB,SAAsB;;;;;wBAuErF,UAAU,2BAA2B"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/random.ts","../src/distributions.ts"],"mappings":";;;;;;;;KASY;;wBAGI,WAAW,eAAe;;;;;;;;;;wBAsB1B,QAAQ,cAAc;WAAqB;;;wBAiC3C,OAAO;;wBAOP,WAAW,cAAc;UAIxB;;WAEN;;EAET;;EAEA,IAAI,aAAa;;EAEjB,MAAM;;EAEN,MAAM,aAAa;;EAEnB,OAAO;;EAEP,KAAK,GAAG,gBAAgB,MAAM;;EAE9B,SAAS;;EAET,QAAQ,GAAG,gBAAgB,MAAM;;EAEjC,OAAO,GAAG,gBAAgB,KAAK,YAAY;;EAE3C,OAAO,eAAe;;EAEtB,KAAK,gBAAgB;;;wBAQP,OAAO,uBAAuB,UAAS,iBAAiB,SAAsB;;wBAM9E,SAAS,MAAM,QAAQ,cAAc,UAAS,iBAAiB,SAAsB;;;;;wBAuErF,UAAU,2BAA2B;;KCtLzC,2BAA2B,aAAa;;KAGxC;WACG;WAA8B,IAAI;WAAgB,OAAO;;WACzD;WAA2B,OAAO;WAAgB,OAAO;;WACzD;WAAyB;WAAoB,UAAU;;WACvD;WAAyB,GAAG;WAAgB,GAAG;;WAC/C;WAA4B;aAA2B;aAAyB,MAAM;;;WACtF;WAA6B;;;;;;wBAsD5B,QAAQ,MAAM,kBAAkB,GAAG;;;;;wBAkDnC,cAAc,MAAM"}
package/build/index.js CHANGED
@@ -1,3 +1,102 @@
1
+ // src/distributions.ts
2
+ /** This function examines a parameter. Both ends of a range must pass `valid`. */
3
+ function checked(family, name, param, valid, rule) {
4
+ const ends = typeof param === "number" ? [param] : param;
5
+ for (const value of ends) if (!Number.isFinite(value) || !valid(value)) throw new RangeError(`${family}: ${name} is ${value}, and it must be ${rule}.`);
6
+ if (typeof param !== "number" && param[0] > param[1]) throw new RangeError(`${family}: the range of ${name} starts above its end.`);
7
+ }
8
+ /** This function gives the value of a parameter: the number, or one draw from the range. */
9
+ function valueOf(param, r) {
10
+ return typeof param === "number" ? param : r.range(param[0], param[1]);
11
+ }
12
+ /** This function gives a gamma sample with the scale 1 (Marsaglia and Tsang, 2000). A shape below 1 uses the boost `U^(1/shape)`. */
13
+ function gamma(r, shape) {
14
+ if (shape < 1) return gamma(r, shape + 1) * Math.pow(1 - r.next(), 1 / shape);
15
+ const d = shape - 1 / 3;
16
+ const c = 1 / Math.sqrt(9 * d);
17
+ for (;;) {
18
+ const x = r.normal();
19
+ const v = (1 + c * x) ** 3;
20
+ if (v <= 0) continue;
21
+ if (Math.log(1 - r.next()) < .5 * x * x + d - d * v + d * Math.log(v)) return d * v;
22
+ }
23
+ }
24
+ /** This function gives the sampler of the ranks from 1 to `n`, with a probability in proportion to `rank^-exponent`. */
25
+ function zipfSampler(n, exponent, r) {
26
+ const totals = [];
27
+ let total = 0;
28
+ for (let rank = 1; rank <= n; rank++) {
29
+ total += Math.pow(rank, -exponent);
30
+ totals.push(total);
31
+ }
32
+ return () => {
33
+ const at = r.next() * total;
34
+ let lo = 0;
35
+ let hi = n - 1;
36
+ while (lo < hi) {
37
+ const mid = lo + hi >>> 1;
38
+ if (totals[mid] > at) hi = mid;
39
+ else lo = mid + 1;
40
+ }
41
+ return lo + 1;
42
+ };
43
+ }
44
+ /**
45
+ * This function gives a sampler of a family. It fixes each parameter once, so a range gives one point of the family.
46
+ * Each call of the sampler gives one number. The same seed and the same spec give the same numbers on one platform.
47
+ */
48
+ function sampler(spec, r) {
49
+ switch (spec.family) {
50
+ case "lognormal": {
51
+ checked("lognormal", "sigma", spec.sigma, (v) => v >= 0, "0 or more");
52
+ checked("lognormal", "mu", spec.mu, () => true, "finite");
53
+ const mu = valueOf(spec.mu, r);
54
+ const sigma = valueOf(spec.sigma, r);
55
+ return () => Math.exp(r.normal(mu, sigma));
56
+ }
57
+ case "pareto": {
58
+ checked("pareto", "scale", spec.scale, (v) => v > 0, "above 0");
59
+ checked("pareto", "shape", spec.shape, (v) => v > 0, "above 0");
60
+ const scale = valueOf(spec.scale, r);
61
+ const shape = valueOf(spec.shape, r);
62
+ return () => scale / Math.pow(1 - r.next(), 1 / shape);
63
+ }
64
+ case "zipf":
65
+ if (!Number.isSafeInteger(spec.n) || spec.n < 1) throw new RangeError(`zipf: n is ${spec.n}, and it must be a whole number of 1 or more.`);
66
+ checked("zipf", "exponent", spec.exponent, (v) => v >= 0, "0 or more");
67
+ return zipfSampler(spec.n, valueOf(spec.exponent, r), r);
68
+ case "beta": {
69
+ checked("beta", "a", spec.a, (v) => v > 0, "above 0");
70
+ checked("beta", "b", spec.b, (v) => v > 0, "above 0");
71
+ const a = valueOf(spec.a, r);
72
+ const b = valueOf(spec.b, r);
73
+ return () => {
74
+ const x = gamma(r, a);
75
+ return x / (x + gamma(r, b));
76
+ };
77
+ }
78
+ case "mixture": {
79
+ if (spec.parts.length === 0) throw new RangeError("mixture: the list of the parts is empty.");
80
+ for (const { weight } of spec.parts) checked("mixture", "weight", weight, (v) => v > 0, "above 0");
81
+ const parts = spec.parts.map(({ part }) => sampler(part, r));
82
+ const weights = spec.parts.map(({ weight }) => weight);
83
+ return () => parts[r.weighted(weights)]();
84
+ }
85
+ case "recorded":
86
+ if (spec.values.length === 0) throw new RangeError("recorded: the list of the values is empty.");
87
+ for (const value of spec.values) checked("recorded", "value", value, () => true, "finite");
88
+ return () => r.pick(spec.values);
89
+ }
90
+ }
91
+ /**
92
+ * This function tells if the numbers of a family use `Math.exp`, `Math.log` or `Math.pow`.
93
+ * The result of those functions can change between JavaScript engines. Thus such a family has the same numbers only on one platform.
94
+ */
95
+ function dependsOnLibm(spec) {
96
+ if (spec.family === "recorded") return false;
97
+ if (spec.family === "mixture") return spec.parts.some(({ part }) => dependsOnLibm(part));
98
+ return true;
99
+ }
1
100
  // src/random.ts
2
101
  /** The generator mulberry32. The seed is read as a 32-bit unsigned integer. */
3
102
  function mulberry32(seed) {
@@ -11,9 +110,43 @@ function mulberry32(seed) {
11
110
  };
12
111
  }
13
112
  const UTF8 = new TextEncoder();
14
- /** The FNV-1a hash of 32 bits of the UTF-8 bytes of a string. */
15
- function fnv1a32(text) {
113
+ /**
114
+ * The FNV-1a hash of 32 bits of a string. The option `input` selects the units that the hash reads:
115
+ *
116
+ * - `"utf8"` (the default): the UTF-8 bytes from `TextEncoder`. A lone surrogate becomes the bytes of U+FFFD.
117
+ * - `"utf16"`: the UTF-16 code units of the string, one unit for each step, from `charCodeAt`.
118
+ * - `"wtf8"`: the UTF-8 bytes of each code point. A lone surrogate becomes its own 3 bytes (WTF-8).
119
+ *
120
+ * For a string without a lone surrogate, `"utf8"` and `"wtf8"` give the same hash.
121
+ */
122
+ function fnv1a32(text, options) {
123
+ const input = options?.input ?? "utf8";
16
124
  let h = 2166136261;
125
+ if (input === "utf16") {
126
+ for (let i = 0; i < text.length; i++) h = Math.imul(h ^ text.charCodeAt(i), 16777619);
127
+ return h >>> 0;
128
+ }
129
+ if (input === "wtf8") {
130
+ for (const ch of text) {
131
+ const c = ch.codePointAt(0);
132
+ if (c < 128) h = Math.imul(h ^ c, 16777619);
133
+ else if (c < 2048) {
134
+ h = Math.imul(h ^ (192 | c >> 6), 16777619);
135
+ h = Math.imul(h ^ (128 | c & 63), 16777619);
136
+ } else if (c < 65536) {
137
+ h = Math.imul(h ^ (224 | c >> 12), 16777619);
138
+ h = Math.imul(h ^ (128 | c >> 6 & 63), 16777619);
139
+ h = Math.imul(h ^ (128 | c & 63), 16777619);
140
+ } else {
141
+ h = Math.imul(h ^ (240 | c >> 18), 16777619);
142
+ h = Math.imul(h ^ (128 | c >> 12 & 63), 16777619);
143
+ h = Math.imul(h ^ (128 | c >> 6 & 63), 16777619);
144
+ h = Math.imul(h ^ (128 | c & 63), 16777619);
145
+ }
146
+ }
147
+ return h >>> 0;
148
+ }
149
+ if (input !== "utf8") throw new RangeError(`fnv1a32: input is "utf8", "utf16" or "wtf8", not ${String(input)}.`);
17
150
  for (const b of UTF8.encode(text)) h = Math.imul(h ^ b, 16777619) >>> 0;
18
151
  return h;
19
152
  }
@@ -111,6 +244,6 @@ function seedsFrom(given, defaults) {
111
244
  if (!Number.isSafeInteger(seed)) throw new RangeError(`seedsFrom: a seed is an integer, not ${given}.`);
112
245
  return [seed];
113
246
  }
114
- export { deriveSeed, fnv1a32, mulberry32, random, randomOf, seedOf, seedsFrom };
247
+ export { dependsOnLibm, deriveSeed, fnv1a32, mulberry32, random, randomOf, sampler, seedOf, seedsFrom };
115
248
 
116
249
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/random.ts"],"sourcesContent":["/**\n * A pseudo-random number generator with a seed, and the draws that tests and benchmarks make from it.\n *\n * The generator is mulberry32. It is fast, it has 32 bits of state and it gives the same sequence for\n * the same seed on each platform. It is not for cryptography. Each repository that copied mulberry32\n * gets the same numbers from `random(seed).next`, so a move to this package keeps the records equal.\n */\n\n/** A source of uniform numbers from 0 (included) to 1 (not included). */\nexport type Source = () => number;\n\n/** The generator mulberry32. The seed is read as a 32-bit unsigned integer. */\nexport function mulberry32(seed: number): Source {\n let state = seed >>> 0;\n return () => {\n state = (state + 0x6d2b79f5) >>> 0;\n let t = state;\n t = Math.imul(t ^ (t >>> 15), t | 1);\n t ^= t + Math.imul(t ^ (t >>> 7), t | 61);\n return ((t ^ (t >>> 14)) >>> 0) / 4294967296;\n };\n}\n\nconst UTF8 = new TextEncoder();\n\n/** The FNV-1a hash of 32 bits of the UTF-8 bytes of a string. */\nexport function fnv1a32(text: string): number {\n let h = 0x811c9dc5;\n for (const b of UTF8.encode(text)) h = Math.imul(h ^ b, 0x01000193) >>> 0;\n return h;\n}\n\n/** The 32-bit seed of a number (its low 32 bits, unsigned) or of a string (its FNV-1a hash). */\nexport function seedOf(seed: number | string): number {\n if (typeof seed === \"string\") return fnv1a32(seed);\n if (!Number.isFinite(seed)) throw new RangeError(`seedOf: a seed is a finite number or a string, not ${seed}.`);\n return seed >>> 0;\n}\n\n/** The seed of the stream with the name `label` under `seed`: the hash of `\"<seed>:<label>\"`. */\nexport function deriveSeed(seed: number, label: string): number {\n return fnv1a32(`${seed}:${label}`);\n}\n\nexport interface Random {\n /** The 32-bit seed that the generator started with. Write it in each failure message, so a run can replay. */\n readonly seed: number;\n /** A uniform number from 0 (included) to 1 (not included). */\n next(): number;\n /** A uniform integer from `min` to `max`, both included. */\n int(min: number, max: number): number;\n /** A uniform integer from 0 (included) to `n` (not included). */\n below(n: number): number;\n /** A uniform number from `min` (included) to `max` (not included). */\n range(min: number, max: number): number;\n /** `true` with the probability `p`. */\n chance(p: number): boolean;\n /** One item of a list that is not empty, each with the same probability. */\n pick<T>(items: readonly T[]): T;\n /** The index of a weight, with a probability in proportion to the weight. One draw. */\n weighted(weights: readonly number[]): number;\n /** A new list with the items in a uniform random order (Fisher–Yates, from the end). */\n shuffle<T>(items: readonly T[]): T[];\n /** `k` different items of a list, in the order of the draw (a partial Fisher–Yates). */\n sample<T>(items: readonly T[], k: number): T[];\n /** A normal sample (Box–Muller, two draws). */\n normal(mean?: number, sd?: number): number;\n /** An independent generator for the part of the work with the name `label`. The same labels give the same streams. */\n fork(label: string): Random;\n}\n\nfunction wholeOrThrow(name: string, value: number): void {\n if (!Number.isSafeInteger(value)) throw new RangeError(`${name}: ${value} is not a safe integer.`);\n}\n\n/** A generator with draws, from a seed. The default source is mulberry32. */\nexport function random(seed: number | string, source: (seed: number) => Source = mulberry32): Random {\n const start = seedOf(seed);\n return randomOf(source(start), start, source);\n}\n\n/** A generator with draws, from a source that you give. `fork` uses `source` for the new streams. */\nexport function randomOf(next: Source, seed: number, source: (seed: number) => Source = mulberry32): Random {\n const below = (n: number): number => {\n wholeOrThrow(\"below\", n);\n if (n < 1) throw new RangeError(`below: n is 1 or more, not ${n}.`);\n return Math.floor(next() * n);\n };\n return {\n seed,\n next,\n int(min, max) {\n wholeOrThrow(\"int\", min);\n wholeOrThrow(\"int\", max);\n if (min > max) throw new RangeError(`int: min ${min} is more than max ${max}.`);\n return min + Math.floor(next() * (max - min + 1));\n },\n below,\n range: (min, max) => min + next() * (max - min),\n chance: (p) => next() < p,\n pick(items) {\n if (items.length === 0) throw new RangeError(\"pick: the list is empty.\");\n return items[below(items.length)] as (typeof items)[number];\n },\n weighted(weights) {\n let total = 0;\n for (const w of weights) {\n if (!(Number.isFinite(w) && w >= 0)) throw new RangeError(`weighted: each weight is finite and 0 or more, not ${w}.`);\n total += w;\n }\n if (!(total > 0)) throw new RangeError(\"weighted: the sum of the weights is 0.\");\n let left = next() * total;\n for (let i = 0; i < weights.length; i++) {\n left -= weights[i] as number;\n if (left < 0) return i;\n }\n // Rounding can leave a small remainder: give the last index with a weight.\n for (let i = weights.length - 1; ; i--) if ((weights[i] as number) > 0) return i;\n },\n shuffle(items) {\n const out = [...items];\n for (let i = out.length - 1; i > 0; i--) {\n const j = below(i + 1);\n [out[i], out[j]] = [out[j] as (typeof out)[number], out[i] as (typeof out)[number]];\n }\n return out;\n },\n sample(items, k) {\n wholeOrThrow(\"sample\", k);\n if (k < 0 || k > items.length) throw new RangeError(`sample: k is from 0 to ${items.length}, not ${k}.`);\n const out = [...items];\n for (let i = 0; i < k; i++) {\n const j = i + below(out.length - i);\n [out[i], out[j]] = [out[j] as (typeof out)[number], out[i] as (typeof out)[number]];\n }\n return out.slice(0, k);\n },\n normal(mean = 0, sd = 1) {\n const u1 = Math.max(next(), 1e-12);\n const u2 = next();\n return mean + sd * Math.sqrt(-2 * Math.log(u1)) * Math.cos(2 * Math.PI * u2);\n },\n fork(label) {\n const child = deriveSeed(seed, label);\n return randomOf(source(child), child, source);\n },\n };\n}\n\n/**\n * The seeds of a run: the seed in `given` (the text of an environment variable, for example\n * `process.env.SEED`), else the default seeds. An empty text gives the defaults.\n */\nexport function seedsFrom(given: string | undefined, defaults: readonly number[]): number[] {\n if (given === undefined || given.trim() === \"\") return [...defaults];\n const seed = Number(given);\n if (!Number.isSafeInteger(seed)) throw new RangeError(`seedsFrom: a seed is an integer, not ${given}.`);\n return [seed];\n}\n"],"mappings":";;AAYA,SAAgB,WAAW,MAAsB;CAC/C,IAAI,QAAQ,SAAS;CACrB,aAAa;EACX,QAAS,QAAQ,eAAgB;EACjC,IAAI,IAAI;EACR,IAAI,KAAK,KAAK,IAAK,MAAM,IAAK,IAAI,CAAC;EACnC,KAAK,IAAI,KAAK,KAAK,IAAK,MAAM,GAAI,IAAI,EAAE;EACxC,SAAS,IAAK,MAAM,QAAS,KAAK;CACpC;AACF;AAEA,MAAM,OAAO,IAAI,YAAY;;AAG7B,SAAgB,QAAQ,MAAsB;CAC5C,IAAI,IAAI;CACR,KAAK,MAAM,KAAK,KAAK,OAAO,IAAI,GAAG,IAAI,KAAK,KAAK,IAAI,GAAG,QAAU,MAAM;CACxE,OAAO;AACT;;AAGA,SAAgB,OAAO,MAA+B;CACpD,IAAI,OAAO,SAAS,UAAU,OAAO,QAAQ,IAAI;CACjD,IAAI,CAAC,OAAO,SAAS,IAAI,GAAG,MAAM,IAAI,WAAW,sDAAsD,KAAK,EAAE;CAC9G,OAAO,SAAS;AAClB;;AAGA,SAAgB,WAAW,MAAc,OAAuB;CAC9D,OAAO,QAAQ,GAAG,KAAK,GAAG,OAAO;AACnC;AA6BA,SAAS,aAAa,MAAc,OAAqB;CACvD,IAAI,CAAC,OAAO,cAAc,KAAK,GAAG,MAAM,IAAI,WAAW,GAAG,KAAK,IAAI,MAAM,wBAAwB;AACnG;;AAGA,SAAgB,OAAO,MAAuB,SAAmC,YAAoB;CACnG,MAAM,QAAQ,OAAO,IAAI;CACzB,OAAO,SAAS,OAAO,KAAK,GAAG,OAAO,MAAM;AAC9C;;AAGA,SAAgB,SAAS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CAAC;IACrB,CAAC,IAAI,IAAI,IAAI,MAAM,CAAC,IAAI,IAA4B,IAAI,EAA0B;GACpF;GACA,OAAO;EACT;EACA,OAAO,OAAO,GAAG;GACf,aAAa,UAAU,CAAC;GACxB,IAAI,IAAI,KAAK,IAAI,MAAM,QAAQ,MAAM,IAAI,WAAW,0BAA0B,MAAM,OAAO,QAAQ,EAAE,EAAE;GACvG,MAAM,MAAM,CAAC,GAAG,KAAK;GACrB,KAAK,IAAI,IAAI,GAAG,IAAI,GAAG,KAAK;IAC1B,MAAM,IAAI,IAAI,MAAM,IAAI,SAAS,CAAC;IAClC,CAAC,IAAI,IAAI,IAAI,MAAM,CAAC,IAAI,IAA4B,IAAI,EAA0B;GACpF;GACA,OAAO,IAAI,MAAM,GAAG,CAAC;EACvB;EACA,OAAO,OAAO,GAAG,KAAK,GAAG;GACvB,MAAM,KAAK,KAAK,IAAI,KAAK,GAAG,KAAK;GACjC,MAAM,KAAK,KAAK;GAChB,OAAO,OAAO,KAAK,KAAK,KAAK,KAAK,KAAK,IAAI,EAAE,CAAC,IAAI,KAAK,IAAI,IAAI,KAAK,KAAK,EAAE;EAC7E;EACA,KAAK,OAAO;GACV,MAAM,QAAQ,WAAW,MAAM,KAAK;GACpC,OAAO,SAAS,OAAO,KAAK,GAAG,OAAO,MAAM;EAC9C;CACF;AACF;;;;;AAMA,SAAgB,UAAU,OAA2B,UAAuC;CAC1F,IAAI,UAAU,KAAA,KAAa,MAAM,KAAK,MAAM,IAAI,OAAO,CAAC,GAAG,QAAQ;CACnE,MAAM,OAAO,OAAO,KAAK;CACzB,IAAI,CAAC,OAAO,cAAc,IAAI,GAAG,MAAM,IAAI,WAAW,wCAAwC,MAAM,EAAE;CACtG,OAAO,CAAC,IAAI;AACd"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/distributions.ts","../src/random.ts"],"sourcesContent":["// Open families of distributions for generated inputs. A family has parameters, and a parameter can be a range.\n// A corpus names a point of a family, so a new size distribution does not need a new closed value.\nimport type { Random } from \"./random.ts\";\n\n/** A parameter of a family: one value, or a range from `min` to `max` that `sampler` draws from once. */\nexport type Param = number | readonly [min: number, max: number];\n\n/** A family of distributions and its parameters. */\nexport type DistributionSpec =\n | { readonly family: \"lognormal\"; readonly mu: Param; readonly sigma: Param }\n | { readonly family: \"pareto\"; readonly scale: Param; readonly shape: Param }\n | { readonly family: \"zipf\"; readonly n: number; readonly exponent: Param }\n | { readonly family: \"beta\"; readonly a: Param; readonly b: Param }\n | { readonly family: \"mixture\"; readonly parts: readonly { readonly weight: number; readonly part: DistributionSpec }[] }\n | { readonly family: \"recorded\"; readonly values: readonly number[] };\n\n/** This function examines a parameter. Both ends of a range must pass `valid`. */\nfunction checked(family: string, name: string, param: Param, valid: (value: number) => boolean, rule: string): void {\n const ends = typeof param === \"number\" ? [param] : param;\n for (const value of ends) {\n if (!Number.isFinite(value) || !valid(value)) throw new RangeError(`${family}: ${name} is ${value}, and it must be ${rule}.`);\n }\n if (typeof param !== \"number\" && param[0] > param[1]) throw new RangeError(`${family}: the range of ${name} starts above its end.`);\n}\n\n/** This function gives the value of a parameter: the number, or one draw from the range. */\nfunction valueOf(param: Param, r: Random): number {\n return typeof param === \"number\" ? param : r.range(param[0], param[1]);\n}\n\n/** This function gives a gamma sample with the scale 1 (Marsaglia and Tsang, 2000). A shape below 1 uses the boost `U^(1/shape)`. */\nfunction gamma(r: Random, shape: number): number {\n if (shape < 1) return gamma(r, shape + 1) * Math.pow(1 - r.next(), 1 / shape);\n const d = shape - 1 / 3;\n const c = 1 / Math.sqrt(9 * d);\n for (;;) {\n const x = r.normal();\n const v = (1 + c * x) ** 3;\n if (v <= 0) continue;\n if (Math.log(1 - r.next()) < 0.5 * x * x + d - d * v + d * Math.log(v)) return d * v;\n }\n}\n\n/** This function gives the sampler of the ranks from 1 to `n`, with a probability in proportion to `rank^-exponent`. */\nfunction zipfSampler(n: number, exponent: number, r: Random): () => number {\n const totals: number[] = [];\n let total = 0;\n for (let rank = 1; rank <= n; rank++) {\n total += Math.pow(rank, -exponent);\n totals.push(total);\n }\n return () => {\n const at = r.next() * total;\n let lo = 0;\n let hi = n - 1;\n while (lo < hi) {\n const mid = (lo + hi) >>> 1;\n if (totals[mid]! > at) hi = mid;\n else lo = mid + 1;\n }\n return lo + 1;\n };\n}\n\n/**\n * This function gives a sampler of a family. It fixes each parameter once, so a range gives one point of the family.\n * Each call of the sampler gives one number. The same seed and the same spec give the same numbers on one platform.\n */\nexport function sampler(spec: DistributionSpec, r: Random): () => number {\n switch (spec.family) {\n case \"lognormal\": {\n checked(\"lognormal\", \"sigma\", spec.sigma, (v) => v >= 0, \"0 or more\");\n checked(\"lognormal\", \"mu\", spec.mu, () => true, \"finite\");\n const mu = valueOf(spec.mu, r);\n const sigma = valueOf(spec.sigma, r);\n return () => Math.exp(r.normal(mu, sigma));\n }\n case \"pareto\": {\n checked(\"pareto\", \"scale\", spec.scale, (v) => v > 0, \"above 0\");\n checked(\"pareto\", \"shape\", spec.shape, (v) => v > 0, \"above 0\");\n const scale = valueOf(spec.scale, r);\n const shape = valueOf(spec.shape, r);\n return () => scale / Math.pow(1 - r.next(), 1 / shape);\n }\n case \"zipf\": {\n if (!Number.isSafeInteger(spec.n) || spec.n < 1) throw new RangeError(`zipf: n is ${spec.n}, and it must be a whole number of 1 or more.`);\n checked(\"zipf\", \"exponent\", spec.exponent, (v) => v >= 0, \"0 or more\");\n return zipfSampler(spec.n, valueOf(spec.exponent, r), r);\n }\n case \"beta\": {\n checked(\"beta\", \"a\", spec.a, (v) => v > 0, \"above 0\");\n checked(\"beta\", \"b\", spec.b, (v) => v > 0, \"above 0\");\n const a = valueOf(spec.a, r);\n const b = valueOf(spec.b, r);\n return () => {\n const x = gamma(r, a);\n return x / (x + gamma(r, b));\n };\n }\n case \"mixture\": {\n if (spec.parts.length === 0) throw new RangeError(\"mixture: the list of the parts is empty.\");\n for (const { weight } of spec.parts) checked(\"mixture\", \"weight\", weight, (v) => v > 0, \"above 0\");\n const parts = spec.parts.map(({ part }) => sampler(part, r));\n const weights = spec.parts.map(({ weight }) => weight);\n return () => parts[r.weighted(weights)]!();\n }\n case \"recorded\": {\n if (spec.values.length === 0) throw new RangeError(\"recorded: the list of the values is empty.\");\n for (const value of spec.values) checked(\"recorded\", \"value\", value, () => true, \"finite\");\n return () => r.pick(spec.values);\n }\n }\n}\n\n/**\n * This function tells if the numbers of a family use `Math.exp`, `Math.log` or `Math.pow`.\n * The result of those functions can change between JavaScript engines. Thus such a family has the same numbers only on one platform.\n */\nexport function dependsOnLibm(spec: DistributionSpec): boolean {\n if (spec.family === \"recorded\") return false;\n if (spec.family === \"mixture\") return spec.parts.some(({ part }) => dependsOnLibm(part));\n return true;\n}\n","/**\n * A pseudo-random number generator with a seed, and the draws that tests and benchmarks make from it.\n *\n * The generator is mulberry32. It is fast, it has 32 bits of state and it gives the same sequence for\n * the same seed on each platform. It is not for cryptography. Each repository that copied mulberry32\n * gets the same numbers from `random(seed).next`, so a move to this package keeps the records equal.\n */\n\n/** A source of uniform numbers from 0 (included) to 1 (not included). */\nexport type Source = () => number;\n\n/** The generator mulberry32. The seed is read as a 32-bit unsigned integer. */\nexport function mulberry32(seed: number): Source {\n let state = seed >>> 0;\n return () => {\n state = (state + 0x6d2b79f5) >>> 0;\n let t = state;\n t = Math.imul(t ^ (t >>> 15), t | 1);\n t ^= t + Math.imul(t ^ (t >>> 7), t | 61);\n return ((t ^ (t >>> 14)) >>> 0) / 4294967296;\n };\n}\n\nconst UTF8 = new TextEncoder();\n\n/**\n * The FNV-1a hash of 32 bits of a string. The option `input` selects the units that the hash reads:\n *\n * - `\"utf8\"` (the default): the UTF-8 bytes from `TextEncoder`. A lone surrogate becomes the bytes of U+FFFD.\n * - `\"utf16\"`: the UTF-16 code units of the string, one unit for each step, from `charCodeAt`.\n * - `\"wtf8\"`: the UTF-8 bytes of each code point. A lone surrogate becomes its own 3 bytes (WTF-8).\n *\n * For a string without a lone surrogate, `\"utf8\"` and `\"wtf8\"` give the same hash.\n */\nexport function fnv1a32(text: string, options?: { readonly input?: \"utf8\" | \"utf16\" | \"wtf8\" }): number {\n const input = options?.input ?? \"utf8\";\n let h = 0x811c9dc5;\n if (input === \"utf16\") {\n for (let i = 0; i < text.length; i++) h = Math.imul(h ^ text.charCodeAt(i), 0x01000193);\n return h >>> 0;\n }\n if (input === \"wtf8\") {\n for (const ch of text) {\n const c = ch.codePointAt(0) as number;\n if (c < 0x80) h = Math.imul(h ^ c, 0x01000193);\n else if (c < 0x800) {\n h = Math.imul(h ^ (0xc0 | (c >> 6)), 0x01000193);\n h = Math.imul(h ^ (0x80 | (c & 63)), 0x01000193);\n } else if (c < 0x10000) {\n h = Math.imul(h ^ (0xe0 | (c >> 12)), 0x01000193);\n h = Math.imul(h ^ (0x80 | ((c >> 6) & 63)), 0x01000193);\n h = Math.imul(h ^ (0x80 | (c & 63)), 0x01000193);\n } else {\n h = Math.imul(h ^ (0xf0 | (c >> 18)), 0x01000193);\n h = Math.imul(h ^ (0x80 | ((c >> 12) & 63)), 0x01000193);\n h = Math.imul(h ^ (0x80 | ((c >> 6) & 63)), 0x01000193);\n h = Math.imul(h ^ (0x80 | (c & 63)), 0x01000193);\n }\n }\n return h >>> 0;\n }\n if (input !== \"utf8\") throw new RangeError(`fnv1a32: input is \"utf8\", \"utf16\" or \"wtf8\", not ${String(input)}.`);\n for (const b of UTF8.encode(text)) h = Math.imul(h ^ b, 0x01000193) >>> 0;\n return h;\n}\n\n/** The 32-bit seed of a number (its low 32 bits, unsigned) or of a string (its FNV-1a hash). */\nexport function seedOf(seed: number | string): number {\n if (typeof seed === \"string\") return fnv1a32(seed);\n if (!Number.isFinite(seed)) throw new RangeError(`seedOf: a seed is a finite number or a string, not ${seed}.`);\n return seed >>> 0;\n}\n\n/** The seed of the stream with the name `label` under `seed`: the hash of `\"<seed>:<label>\"`. */\nexport function deriveSeed(seed: number, label: string): number {\n return fnv1a32(`${seed}:${label}`);\n}\n\nexport interface Random {\n /** The 32-bit seed that the generator started with. Write it in each failure message, so a run can replay. */\n readonly seed: number;\n /** A uniform number from 0 (included) to 1 (not included). */\n next(): number;\n /** A uniform integer from `min` to `max`, both included. */\n int(min: number, max: number): number;\n /** A uniform integer from 0 (included) to `n` (not included). */\n below(n: number): number;\n /** A uniform number from `min` (included) to `max` (not included). */\n range(min: number, max: number): number;\n /** `true` with the probability `p`. */\n chance(p: number): boolean;\n /** One item of a list that is not empty, each with the same probability. */\n pick<T>(items: readonly T[]): T;\n /** The index of a weight, with a probability in proportion to the weight. One draw. */\n weighted(weights: readonly number[]): number;\n /** A new list with the items in a uniform random order (Fisher–Yates, from the end). */\n shuffle<T>(items: readonly T[]): T[];\n /** `k` different items of a list, in the order of the draw (a partial Fisher–Yates). */\n sample<T>(items: readonly T[], k: number): T[];\n /** A normal sample (Box–Muller, two draws). */\n normal(mean?: number, sd?: number): number;\n /** An independent generator for the part of the work with the name `label`. The same labels give the same streams. */\n fork(label: string): Random;\n}\n\nfunction wholeOrThrow(name: string, value: number): void {\n if (!Number.isSafeInteger(value)) throw new RangeError(`${name}: ${value} is not a safe integer.`);\n}\n\n/** A generator with draws, from a seed. The default source is mulberry32. */\nexport function random(seed: number | string, source: (seed: number) => Source = mulberry32): Random {\n const start = seedOf(seed);\n return randomOf(source(start), start, source);\n}\n\n/** A generator with draws, from a source that you give. `fork` uses `source` for the new streams. */\nexport function randomOf(next: Source, seed: number, source: (seed: number) => Source = mulberry32): Random {\n const below = (n: number): number => {\n wholeOrThrow(\"below\", n);\n if (n < 1) throw new RangeError(`below: n is 1 or more, not ${n}.`);\n return Math.floor(next() * n);\n };\n return {\n seed,\n next,\n int(min, max) {\n wholeOrThrow(\"int\", min);\n wholeOrThrow(\"int\", max);\n if (min > max) throw new RangeError(`int: min ${min} is more than max ${max}.`);\n return min + Math.floor(next() * (max - min + 1));\n },\n below,\n range: (min, max) => min + next() * (max - min),\n chance: (p) => next() < p,\n pick(items) {\n if (items.length === 0) throw new RangeError(\"pick: the list is empty.\");\n return items[below(items.length)] as (typeof items)[number];\n },\n weighted(weights) {\n let total = 0;\n for (const w of weights) {\n if (!(Number.isFinite(w) && w >= 0)) throw new RangeError(`weighted: each weight is finite and 0 or more, not ${w}.`);\n total += w;\n }\n if (!(total > 0)) throw new RangeError(\"weighted: the sum of the weights is 0.\");\n let left = next() * total;\n for (let i = 0; i < weights.length; i++) {\n left -= weights[i] as number;\n if (left < 0) return i;\n }\n // Rounding can leave a small remainder: give the last index with a weight.\n for (let i = weights.length - 1; ; i--) if ((weights[i] as number) > 0) return i;\n },\n shuffle(items) {\n const out = [...items];\n for (let i = out.length - 1; i > 0; i--) {\n const j = below(i + 1);\n [out[i], out[j]] = [out[j] as (typeof out)[number], out[i] as (typeof out)[number]];\n }\n return out;\n },\n sample(items, k) {\n wholeOrThrow(\"sample\", k);\n if (k < 0 || k > items.length) throw new RangeError(`sample: k is from 0 to ${items.length}, not ${k}.`);\n const out = [...items];\n for (let i = 0; i < k; i++) {\n const j = i + below(out.length - i);\n [out[i], out[j]] = [out[j] as (typeof out)[number], out[i] as (typeof out)[number]];\n }\n return out.slice(0, k);\n },\n normal(mean = 0, sd = 1) {\n const u1 = Math.max(next(), 1e-12);\n const u2 = next();\n return mean + sd * Math.sqrt(-2 * Math.log(u1)) * Math.cos(2 * Math.PI * u2);\n },\n fork(label) {\n const child = deriveSeed(seed, label);\n return randomOf(source(child), child, source);\n },\n };\n}\n\n/**\n * The seeds of a run: the seed in `given` (the text of an environment variable, for example\n * `process.env.SEED`), else the default seeds. An empty text gives the defaults.\n */\nexport function seedsFrom(given: string | undefined, defaults: readonly number[]): number[] {\n if (given === undefined || given.trim() === \"\") return [...defaults];\n const seed = Number(given);\n if (!Number.isSafeInteger(seed)) throw new RangeError(`seedsFrom: a seed is an integer, not ${given}.`);\n return [seed];\n}\n"],"mappings":";;AAiBA,SAAS,QAAQ,QAAgB,MAAc,OAAc,OAAmC,MAAoB;CAClH,MAAM,OAAO,OAAO,UAAU,WAAW,CAAC,KAAK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,UAAU,OAA2B,UAAuC;CAC1F,IAAI,UAAU,KAAA,KAAa,MAAM,KAAK,MAAM,IAAI,OAAO,CAAC,GAAG,QAAQ;CACnE,MAAM,OAAO,OAAO,KAAK;CACzB,IAAI,CAAC,OAAO,cAAc,IAAI,GAAG,MAAM,IAAI,WAAW,wCAAwC,MAAM,EAAE;CACtG,OAAO,CAAC,IAAI;AACd"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package",
3
3
  "name": "@mark1russell7/rigor-generators",
4
- "version": "0.1.0",
4
+ "version": "0.1.2",
5
5
  "description": "A seeded random number generator (mulberry32) with the draws that tests and benchmarks make: integers, picks, weights, shuffles, samples, normal values and named streams.",
6
6
  "keywords": [
7
7
  "random",
@@ -38,7 +38,7 @@
38
38
  "node": ">=22"
39
39
  },
40
40
  "devDependencies": {
41
- "@mark1russell7/cue": "^1.0.2",
41
+ "@mark1russell7/cue": "^2.0.0",
42
42
  "@types/node": "^26.6.5",
43
43
  "tsdown": "^0.23.1",
44
44
  "typescript": "^7.0.2",