@mark1russell7/rigor-generators 0.1.14 → 0.1.16

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
@@ -49,6 +49,19 @@ stablePick(deriveSeed(7, "origin"), ["tall-row", "ladder", "half-wide"]);
49
49
  - When a list loses an item, only the draws of that item change.
50
50
  - A choice reads one hash for each item, so it costs O(n). `r.pick` costs O(1).
51
51
 
52
+ ## A weighted random order
53
+
54
+ `plackettLuceOrder(seed, items, logWeightOf, keyOf)` gives a random order of a list with the Plackett-Luce law of the weights. It adds a Gumbel draw to the log-weight of each item, and it sorts from the largest sum (the Gumbel-max method):
55
+
56
+ ```ts
57
+ plackettLuceOrder("feed-7", posts, (post) => Math.log(post.score), (post) => post.id);
58
+ ```
59
+
60
+ - The first item is item `i` with the probability `w_i / sum(w)`. Each next item has the same law over the items that remain.
61
+ - The draw of an item comes from the stream `random(seed).fork(key)`. Thus a new item or a lost item does not change the order of the other items.
62
+ - An item with the log-weight `-Infinity` (the weight 0) comes last. Items with equal sums keep the order of the list.
63
+ - Each key occurs once. A log-weight of NaN or `+Infinity` is a `RangeError`.
64
+
52
65
  ## Open families of distributions
53
66
 
54
67
  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.
package/build/index.d.ts CHANGED
@@ -4,5 +4,5 @@ import { Distribution, betaCdf, distributionOf } from "./quantiles.js";
4
4
  import { Dimension, InputFamily, Point, SaltelliDesign, familyMap, familyPoints, latinHypercube, randomDesign, saltelliDesign, stratifiedDesign } from "./designs.js";
5
5
  import { CanonicalOptions, Sha256Options, canonicalHash, canonicalJson, sha256Hex } from "./hash.js";
6
6
  import { DIAGRAM_BOX_AREA, GIT_BLOB_BYTES, RECORDED_TABLES, RecordedTable, recordedSpec } from "./recorded.js";
7
- import { Random, Source, deriveSeed, fnv1a32, mulberry32, random, randomOf, seedOf, seedsFrom, stablePick } from "./random.js";
8
- export { type CanonicalOptions, DIAGRAM_BOX_AREA, type Dimension, type Distribution, type DistributionSpec, GIT_BLOB_BYTES, type InputFamily, type Param, type Point, RECORDED_TABLES, type Random, type RecordedTable, type SaltelliDesign, type Sha256Options, type Source, betaCdf, canonicalHash, canonicalJson, dependsOnLibm, deriveSeed, distributionOf, familyMap, familyPoints, fnv1a32, latinHypercube, mulberry32, normalCdf, normalQuantile, random, randomDesign, randomOf, recordedSpec, saltelliDesign, sampler, seedOf, seedsFrom, sha256Hex, stablePick, stratifiedDesign };
7
+ import { Random, Source, deriveSeed, fnv1a32, mulberry32, plackettLuceOrder, random, randomOf, seedOf, seedsFrom, stablePick } from "./random.js";
8
+ export { type CanonicalOptions, DIAGRAM_BOX_AREA, type Dimension, type Distribution, type DistributionSpec, GIT_BLOB_BYTES, type InputFamily, type Param, type Point, RECORDED_TABLES, type Random, type RecordedTable, type SaltelliDesign, type Sha256Options, type Source, betaCdf, canonicalHash, canonicalJson, dependsOnLibm, deriveSeed, distributionOf, familyMap, familyPoints, fnv1a32, latinHypercube, mulberry32, normalCdf, normalQuantile, plackettLuceOrder, random, randomDesign, randomOf, recordedSpec, saltelliDesign, sampler, seedOf, seedsFrom, sha256Hex, stablePick, stratifiedDesign };
package/build/index.js CHANGED
@@ -4,5 +4,5 @@ import { betaCdf, distributionOf } from "./quantiles.js";
4
4
  import { familyMap, familyPoints, latinHypercube, randomDesign, saltelliDesign, stratifiedDesign } from "./designs.js";
5
5
  import { canonicalHash, canonicalJson, sha256Hex } from "./hash.js";
6
6
  import { DIAGRAM_BOX_AREA, GIT_BLOB_BYTES, RECORDED_TABLES, recordedSpec } from "./recorded.js";
7
- import { deriveSeed, fnv1a32, mulberry32, random, randomOf, seedOf, seedsFrom, stablePick } from "./random.js";
8
- export { DIAGRAM_BOX_AREA, GIT_BLOB_BYTES, RECORDED_TABLES, betaCdf, canonicalHash, canonicalJson, dependsOnLibm, deriveSeed, distributionOf, familyMap, familyPoints, fnv1a32, latinHypercube, mulberry32, normalCdf, normalQuantile, random, randomDesign, randomOf, recordedSpec, saltelliDesign, sampler, seedOf, seedsFrom, sha256Hex, stablePick, stratifiedDesign };
7
+ import { deriveSeed, fnv1a32, mulberry32, plackettLuceOrder, random, randomOf, seedOf, seedsFrom, stablePick } from "./random.js";
8
+ export { DIAGRAM_BOX_AREA, GIT_BLOB_BYTES, RECORDED_TABLES, betaCdf, canonicalHash, canonicalJson, dependsOnLibm, deriveSeed, distributionOf, familyMap, familyPoints, fnv1a32, latinHypercube, mulberry32, normalCdf, normalQuantile, plackettLuceOrder, random, randomDesign, randomOf, recordedSpec, saltelliDesign, sampler, seedOf, seedsFrom, sha256Hex, stablePick, stratifiedDesign };
package/build/random.d.ts CHANGED
@@ -36,6 +36,18 @@ export declare function deriveSeed(seed: number, label: string): number;
36
36
  * The function reads one hash for each item, so a choice costs O(n). The list is not empty, and each key occurs once.
37
37
  */
38
38
  export declare function stablePick<T>(seed: number, items: readonly T[], keyOf?: (item: T) => string): T;
39
+ /**
40
+ * A random order of a list with the Plackett-Luce law of the weights (the Gumbel-max method). Each item gets the sum of
41
+ * its log-weight and a Gumbel draw. The order goes from the largest sum to the smallest.
42
+ *
43
+ * - The first item is item `i` with the probability `w_i / sum(w)`. Each next item has the same law over the items that remain.
44
+ * - The draw of an item comes from the stream `random(seed).fork(key)`. Thus a new item or a lost item does not change the order of the other items.
45
+ * - Items with equal sums keep the order of the list. Thus the items with the log-weight `-Infinity` come last, in the order of the list.
46
+ *
47
+ * The function reads one draw for each item, and it does not change its inputs. Each key occurs once. A log-weight is
48
+ * finite or `-Infinity`.
49
+ */
50
+ export declare function plackettLuceOrder<T>(seed: number | string, items: readonly T[], logWeightOf: (item: T) => number, keyOf?: (item: T) => string): T[];
39
51
  export interface Random {
40
52
  /** The 32-bit seed that the generator started with. Write it in each failure message, so a run can replay. */
41
53
  readonly seed: number;
@@ -1 +1 @@
1
- {"version":3,"file":"random.d.ts","names":[],"sources":["../src/random.ts"],"mappings":";;;;;;;;YAS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O,uBAAuB,UAAS,iBAAiB,SAAsB;;wBAM9E,SAAS,MAAM,QAAQ,cAAc,UAAS,iBAAiB,SAAsB;;;;;;;;;wBAoFrF,UAAU,2BAA2B"}
package/build/random.js CHANGED
@@ -85,6 +85,30 @@ function stablePick(seed, items, keyOf = String) {
85
85
  }
86
86
  return best.item;
87
87
  }
88
+ /**
89
+ * A random order of a list with the Plackett-Luce law of the weights (the Gumbel-max method). Each item gets the sum of
90
+ * its log-weight and a Gumbel draw. The order goes from the largest sum to the smallest.
91
+ *
92
+ * - The first item is item `i` with the probability `w_i / sum(w)`. Each next item has the same law over the items that remain.
93
+ * - The draw of an item comes from the stream `random(seed).fork(key)`. Thus a new item or a lost item does not change the order of the other items.
94
+ * - Items with equal sums keep the order of the list. Thus the items with the log-weight `-Infinity` come last, in the order of the list.
95
+ *
96
+ * The function reads one draw for each item, and it does not change its inputs. Each key occurs once. A log-weight is
97
+ * finite or `-Infinity`.
98
+ */
99
+ function plackettLuceOrder(seed, items, logWeightOf, keyOf = String) {
100
+ const root = random(seed);
101
+ const seen = /* @__PURE__ */ new Set();
102
+ const sums = items.map((item) => {
103
+ const key = keyOf(item);
104
+ if (seen.has(key)) throw new RangeError(`plackettLuceOrder: the key ${JSON.stringify(key)} occurs twice.`);
105
+ seen.add(key);
106
+ const logWeight = logWeightOf(item);
107
+ if (Number.isNaN(logWeight) || logWeight === Number.POSITIVE_INFINITY) throw new RangeError(`plackettLuceOrder: the log-weight of the key ${JSON.stringify(key)} is ${logWeight}, and a log-weight is finite or -Infinity.`);
108
+ return logWeight + root.fork(key).gumbel();
109
+ });
110
+ return items.map((_, index) => index).sort((x, y) => sums[y] - sums[x] || x - y).map((index) => items[index]);
111
+ }
88
112
  function wholeOrThrow(name, value) {
89
113
  if (!Number.isSafeInteger(value)) throw new RangeError(`${name}: ${value} is not a safe integer.`);
90
114
  }
@@ -189,6 +213,6 @@ function seedsFrom(given, defaults) {
189
213
  return [seed];
190
214
  });
191
215
  }
192
- export { deriveSeed, fnv1a32, mulberry32, random, randomOf, seedOf, seedsFrom, stablePick };
216
+ export { deriveSeed, fnv1a32, mulberry32, plackettLuceOrder, random, randomOf, seedOf, seedsFrom, stablePick };
193
217
 
194
218
  //# sourceMappingURL=random.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"random.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\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, equal to the bytes of `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. The function uses no API of Node or\n * of the browser, so the hash is the same on each platform.\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 !== \"utf8\" && input !== \"wtf8\") throw new RangeError(`fnv1a32: input is \"utf8\", \"utf16\" or \"wtf8\", not ${String(input)}.`);\n for (const ch of text) {\n let c = ch.codePointAt(0) as number;\n // A string iterator gives a lone surrogate as one code point. UTF-8 writes U+FFFD in its place, as TextEncoder does.\n if (input === \"utf8\" && c >= 0xd800 && c <= 0xdfff) c = 0xfffd;\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\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\n/**\n * One item of a list, chosen by highest random weight: each key has a weight from `seed`, and the largest weight wins.\n *\n * - The order of the list does not change the choice. The smaller key wins a tie of weights.\n * - When a list gains an item, only the draws that the new item wins change. For `n` items, the share of those draws is approximately `1 / (n + 1)`.\n * - When a list loses an item, only the draws of that item change.\n *\n * The function reads one hash for each item, so a choice costs O(n). The list is not empty, and each key occurs once.\n */\nexport function stablePick<T>(seed: number, items: readonly T[], keyOf: (item: T) => string = String): T {\n if (items.length === 0) throw new RangeError(\"stablePick: the list is empty.\");\n const start = seedOf(seed);\n const seen = new Set<string>();\n let best: { item: T; key: string; weight: number } | undefined;\n for (const item of items) {\n const key = keyOf(item);\n if (seen.has(key)) throw new RangeError(`stablePick: the key ${JSON.stringify(key)} occurs twice.`);\n seen.add(key);\n const weight = mulberry32(deriveSeed(start, key))();\n if (best === undefined || weight > best.weight || (weight === best.weight && key < best.key)) best = { item, key, weight };\n }\n return (best as { item: T }).item;\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 /**\n * A Gumbel sample with the mode `location` and the scale `scale` (the inverse of the CDF, one draw).\n * The mean is `location + 0.5772 * scale`.\n * Add a Gumbel draw with the scale 1 to the log of each weight, and sort by the sums.\n * The order then has the Plackett-Luce law of the weights (the Gumbel-max method).\n */\n gumbel(location?: number, scale?: 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 gumbel(location = 0, scale = 1) {\n if (!(Number.isFinite(scale) && scale > 0)) throw new RangeError(`gumbel: the scale is finite and more than 0, not ${scale}.`);\n // The same floor as normal: a draw of 0 gives a finite value, not minus infinity.\n const u = Math.max(next(), 1e-12);\n return location - scale * Math.log(-Math.log(u));\n },\n fork(label) {\n const child = deriveSeed(seed, label);\n return randomOf(source(child), child, source);\n },\n };\n}\n\n/** The largest count of seeds that one range gives. A larger range is an error, not a long run. */\nconst MAX_RANGE = 1_000_000;\n\n/**\n * The seeds of a run: the seeds 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 *\n * The text is one seed (`17`) or a list of seeds and ranges with commas (`1,3,9-11` gives 1, 3, 9, 10\n * and 11), in the order of the list. A range has two whole numbers, the low one first. An empty part, a\n * part that is not an integer and a range with the low end last are each a `RangeError`.\n */\nexport function seedsFrom(given: string | undefined, defaults: readonly number[]): number[] {\n if (given === undefined || given.trim() === \"\") return [...defaults];\n return given.split(\",\").flatMap((raw) => {\n const part = raw.trim();\n const range = /^(\\d+)\\s*-\\s*(\\d+)$/u.exec(part);\n if (range !== null) {\n const [low, high] = [Number(range[1]), Number(range[2])];\n if (!Number.isSafeInteger(high) || high < low || high - low >= MAX_RANGE) {\n throw new RangeError(`seedsFrom: the range ${part} is not low-high with at most ${MAX_RANGE} seeds.`);\n }\n return Array.from({ length: high - low + 1 }, (_, i) => low + i);\n }\n const seed = part === \"\" ? Number.NaN : Number(part);\n if (!Number.isSafeInteger(seed)) throw new RangeError(`seedsFrom: a seed is an integer, not ${part === \"\" ? \"an empty part\" : part}.`);\n return [seed];\n });\n}\n"],"mappings":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A,KAAa,MAAM,KAAK,MAAM,IAAI,OAAO,CAAC,GAAG,QAAQ;CACnE,OAAO,MAAM,MAAM,GAAG,CAAC,CAAC,SAAS,QAAQ;EACvC,MAAM,OAAO,IAAI,KAAK;EACtB,MAAM,QAAQ,uBAAuB,KAAK,IAAI;EAC9C,IAAI,UAAU,MAAM;GAClB,MAAM,CAAC,KAAK,QAAQ,CAAC,OAAO,MAAM,EAAE,GAAG,OAAO,MAAM,EAAE,CAAC;GACvD,IAAI,CAAC,OAAO,cAAc,IAAI,KAAK,OAAO,OAAO,OAAO,OAAO,WAC7D,MAAM,IAAI,WAAW,wBAAwB,KAAK,gCAAgC,UAAU,QAAQ;GAEtG,OAAO,MAAM,KAAK,EAAE,QAAQ,OAAO,MAAM,EAAE,IAAI,GAAG,MAAM,MAAM,CAAC;EACjE;EACA,MAAM,OAAO,SAAS,KAAK,MAAa,OAAO,IAAI;EACnD,IAAI,CAAC,OAAO,cAAc,IAAI,GAAG,MAAM,IAAI,WAAW,wCAAwC,SAAS,KAAK,kBAAkB,KAAK,EAAE;EACrI,OAAO,CAAC,IAAI;CACd,CAAC;AACH"}
1
+ {"version":3,"file":"random.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\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, equal to the bytes of `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. The function uses no API of Node or\n * of the browser, so the hash is the same on each platform.\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 !== \"utf8\" && input !== \"wtf8\") throw new RangeError(`fnv1a32: input is \"utf8\", \"utf16\" or \"wtf8\", not ${String(input)}.`);\n for (const ch of text) {\n let c = ch.codePointAt(0) as number;\n // A string iterator gives a lone surrogate as one code point. UTF-8 writes U+FFFD in its place, as TextEncoder does.\n if (input === \"utf8\" && c >= 0xd800 && c <= 0xdfff) c = 0xfffd;\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\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\n/**\n * One item of a list, chosen by highest random weight: each key has a weight from `seed`, and the largest weight wins.\n *\n * - The order of the list does not change the choice. The smaller key wins a tie of weights.\n * - When a list gains an item, only the draws that the new item wins change. For `n` items, the share of those draws is approximately `1 / (n + 1)`.\n * - When a list loses an item, only the draws of that item change.\n *\n * The function reads one hash for each item, so a choice costs O(n). The list is not empty, and each key occurs once.\n */\nexport function stablePick<T>(seed: number, items: readonly T[], keyOf: (item: T) => string = String): T {\n if (items.length === 0) throw new RangeError(\"stablePick: the list is empty.\");\n const start = seedOf(seed);\n const seen = new Set<string>();\n let best: { item: T; key: string; weight: number } | undefined;\n for (const item of items) {\n const key = keyOf(item);\n if (seen.has(key)) throw new RangeError(`stablePick: the key ${JSON.stringify(key)} occurs twice.`);\n seen.add(key);\n const weight = mulberry32(deriveSeed(start, key))();\n if (best === undefined || weight > best.weight || (weight === best.weight && key < best.key)) best = { item, key, weight };\n }\n return (best as { item: T }).item;\n}\n\n/**\n * A random order of a list with the Plackett-Luce law of the weights (the Gumbel-max method). Each item gets the sum of\n * its log-weight and a Gumbel draw. The order goes from the largest sum to the smallest.\n *\n * - The first item is item `i` with the probability `w_i / sum(w)`. Each next item has the same law over the items that remain.\n * - The draw of an item comes from the stream `random(seed).fork(key)`. Thus a new item or a lost item does not change the order of the other items.\n * - Items with equal sums keep the order of the list. Thus the items with the log-weight `-Infinity` come last, in the order of the list.\n *\n * The function reads one draw for each item, and it does not change its inputs. Each key occurs once. A log-weight is\n * finite or `-Infinity`.\n */\nexport function plackettLuceOrder<T>(seed: number | string, items: readonly T[], logWeightOf: (item: T) => number, keyOf: (item: T) => string = String): T[] {\n const root = random(seed);\n const seen = new Set<string>();\n const sums = items.map((item) => {\n const key = keyOf(item);\n if (seen.has(key)) throw new RangeError(`plackettLuceOrder: the key ${JSON.stringify(key)} occurs twice.`);\n seen.add(key);\n const logWeight = logWeightOf(item);\n if (Number.isNaN(logWeight) || logWeight === Number.POSITIVE_INFINITY) {\n throw new RangeError(`plackettLuceOrder: the log-weight of the key ${JSON.stringify(key)} is ${logWeight}, and a log-weight is finite or -Infinity.`);\n }\n return logWeight + root.fork(key).gumbel();\n });\n // Two sums of -Infinity give NaN, which is false, so the order of the list decides.\n const order = items.map((_, index) => index).sort((x, y) => (sums[y] as number) - (sums[x] as number) || x - y);\n return order.map((index) => items[index] as T);\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 /**\n * A Gumbel sample with the mode `location` and the scale `scale` (the inverse of the CDF, one draw).\n * The mean is `location + 0.5772 * scale`.\n * Add a Gumbel draw with the scale 1 to the log of each weight, and sort by the sums.\n * The order then has the Plackett-Luce law of the weights (the Gumbel-max method).\n */\n gumbel(location?: number, scale?: 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 gumbel(location = 0, scale = 1) {\n if (!(Number.isFinite(scale) && scale > 0)) throw new RangeError(`gumbel: the scale is finite and more than 0, not ${scale}.`);\n // The same floor as normal: a draw of 0 gives a finite value, not minus infinity.\n const u = Math.max(next(), 1e-12);\n return location - scale * Math.log(-Math.log(u));\n },\n fork(label) {\n const child = deriveSeed(seed, label);\n return randomOf(source(child), child, source);\n },\n };\n}\n\n/** The largest count of seeds that one range gives. A larger range is an error, not a long run. */\nconst MAX_RANGE = 1_000_000;\n\n/**\n * The seeds of a run: the seeds 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 *\n * The text is one seed (`17`) or a list of seeds and ranges with commas (`1,3,9-11` gives 1, 3, 9, 10\n * and 11), in the order of the list. A range has two whole numbers, the low one first. An empty part, a\n * part that is not an integer and a range with the low end last are each a `RangeError`.\n */\nexport function seedsFrom(given: string | undefined, defaults: readonly number[]): number[] {\n if (given === undefined || given.trim() === \"\") return [...defaults];\n return given.split(\",\").flatMap((raw) => {\n const part = raw.trim();\n const range = /^(\\d+)\\s*-\\s*(\\d+)$/u.exec(part);\n if (range !== null) {\n const [low, high] = [Number(range[1]), Number(range[2])];\n if (!Number.isSafeInteger(high) || high < low || high - low >= MAX_RANGE) {\n throw new RangeError(`seedsFrom: the range ${part} is not low-high with at most ${MAX_RANGE} seeds.`);\n }\n return Array.from({ length: high - low + 1 }, (_, i) => low + i);\n }\n const seed = part === \"\" ? Number.NaN : Number(part);\n if (!Number.isSafeInteger(seed)) throw new RangeError(`seedsFrom: a seed is an integer, not ${part === \"\" ? \"an empty part\" : part}.`);\n return [seed];\n });\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;;;;;;;;;;;AAYA,SAAgB,QAAQ,MAAc,SAAkE;CACtG,MAAM,QAAQ,SAAS,SAAS;CAChC,IAAI,IAAI;CACR,IAAI,UAAU,SAAS;EACrB,KAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK,IAAI,KAAK,KAAK,IAAI,KAAK,WAAW,CAAC,GAAG,QAAU;EACtF,OAAO,MAAM;CACf;CACA,IAAI,UAAU,UAAU,UAAU,QAAQ,MAAM,IAAI,WAAW,oDAAoD,OAAO,KAAK,EAAE,EAAE;CACnI,KAAK,MAAM,MAAM,MAAM;EACrB,IAAI,IAAI,GAAG,YAAY,CAAC;EAExB,IAAI,UAAU,UAAU,KAAK,SAAU,KAAK,OAAQ,IAAI;EACxD,IAAI,IAAI,KAAM,IAAI,KAAK,KAAK,IAAI,GAAG,QAAU;OACxC,IAAI,IAAI,MAAO;GAClB,IAAI,KAAK,KAAK,KAAK,MAAQ,KAAK,IAAK,QAAU;GAC/C,IAAI,KAAK,KAAK,KAAK,MAAQ,IAAI,KAAM,QAAU;EACjD,OAAO,IAAI,IAAI,OAAS;GACtB,IAAI,KAAK,KAAK,KAAK,MAAQ,KAAK,KAAM,QAAU;GAChD,IAAI,KAAK,KAAK,KAAK,MAAS,KAAK,IAAK,KAAM,QAAU;GAC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I,WAAW,wBAAwB,KAAK,gCAAgC,UAAU,QAAQ;GAEtG,OAAO,MAAM,KAAK,EAAE,QAAQ,OAAO,MAAM,EAAE,IAAI,GAAG,MAAM,MAAM,CAAC;EACjE;EACA,MAAM,OAAO,SAAS,KAAK,MAAa,OAAO,IAAI;EACnD,IAAI,CAAC,OAAO,cAAc,IAAI,GAAG,MAAM,IAAI,WAAW,wCAAwC,SAAS,KAAK,kBAAkB,KAAK,EAAE;EACrI,OAAO,CAAC,IAAI;CACd,CAAC;AACH"}
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.14",
4
+ "version": "0.1.16",
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. It also gives a content hash: SHA-256 and canonical JSON (RFC 8785).",
6
6
  "keywords": [
7
7
  "random",
@@ -45,6 +45,7 @@
45
45
  "@mark1russell7/cue": "^2.0.0",
46
46
  "@types/node": "^26.6.5",
47
47
  "esbuild": "^0.28.2",
48
+ "fast-check": "^4.10.2",
48
49
  "tsdown": "^0.23.1",
49
50
  "typescript": "^7.0.2",
50
51
  "vitest": "^5.0.3"
@@ -59,7 +60,8 @@
59
60
  "exports": {
60
61
  ".": {
61
62
  "types": "./build/index.d.ts",
62
- "import": "./build/index.js"
63
+ "import": "./build/index.js",
64
+ "default": "./build/index.js"
63
65
  },
64
66
  "./package.json": "./package.json"
65
67
  }