@mark1russell7/rigor-generators 0.0.0-stage → 0.1.0
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/LICENSE +21 -0
- package/README.md +54 -2
- package/build/index.d.ts +54 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +116 -0
- package/build/index.js.map +1 -0
- package/package.json +58 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mark Russell
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,55 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @mark1russell7/rigor-generators
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
A seeded random number generator (mulberry32) with the draws that tests and benchmarks make. It operates in Node and in a browser, and it has no dependencies.
|
|
4
|
+
|
|
5
|
+
The same seed gives the same numbers on each platform. The generator is not for cryptography.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install @mark1russell7/rigor-generators
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Use
|
|
12
|
+
|
|
13
|
+
```ts
|
|
14
|
+
import { random, seedsFrom } from "@mark1russell7/rigor-generators";
|
|
15
|
+
|
|
16
|
+
const r = random(42); // or random("night 2026-10-29"): a text seed is hashed
|
|
17
|
+
r.next(); // a number from 0 (included) to 1 (not included)
|
|
18
|
+
r.int(1, 6); // an integer from 1 to 6, both included
|
|
19
|
+
r.below(10); // an integer from 0 to 9
|
|
20
|
+
r.range(-1, 1); // a number from -1 (included) to 1 (not included)
|
|
21
|
+
r.chance(0.3); // true with the probability 0.3
|
|
22
|
+
r.pick(["a", "b", "c"]); // one item
|
|
23
|
+
r.weighted([1, 2, 3]); // an index: 2 has the probability 3/6
|
|
24
|
+
r.shuffle([1, 2, 3, 4]); // a new list in a random order
|
|
25
|
+
r.sample([1, 2, 3, 4], 2); // 2 different items
|
|
26
|
+
r.normal(10, 2); // a normal value with the mean 10 and the standard deviation 2
|
|
27
|
+
r.fork("lanes"); // an independent generator for one part of the work
|
|
28
|
+
r.seed; // the 32-bit seed: write it in each failure message
|
|
29
|
+
|
|
30
|
+
// The seeds of a run: the seed of the environment variable SEED, else the defaults.
|
|
31
|
+
for (const seed of seedsFrom(process.env.SEED, [1, 2, 3, 4, 5])) {
|
|
32
|
+
// ...
|
|
33
|
+
}
|
|
34
|
+
```
|
|
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).
|
|
37
|
+
|
|
38
|
+
## Move from a copy of mulberry32
|
|
39
|
+
|
|
40
|
+
Each common form of mulberry32 gives the same numbers as `random(seed).next`: the first published form (`| 0` on the state) and the form with `>>> 0`. These also give the same values:
|
|
41
|
+
|
|
42
|
+
| Your code | This package |
|
|
43
|
+
| --- | --- |
|
|
44
|
+
| `min + Math.floor(next() * (max - min + 1))` | `r.int(min, max)` |
|
|
45
|
+
| `Math.floor(next() * n)` | `r.below(n)` |
|
|
46
|
+
| `next() < p` | `r.chance(p)` |
|
|
47
|
+
| `items[Math.floor(next() * items.length)]` | `r.pick(items)` |
|
|
48
|
+
| Box–Muller with `Math.max(next(), 1e-12)` and `cos` | `r.normal()` |
|
|
49
|
+
| `mulberry32(fnv1a32(\`${seed}:${step}\`))` | `random(seed).fork(step)` |
|
|
50
|
+
|
|
51
|
+
The tests of the package compare each form with the package, for many seeds. After a move, start your tests and compare your records: they stay byte-equal.
|
|
52
|
+
|
|
53
|
+
## License
|
|
54
|
+
|
|
55
|
+
MIT
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A pseudo-random number generator with a seed, and the draws that tests and benchmarks make from it.
|
|
3
|
+
*
|
|
4
|
+
* The generator is mulberry32. It is fast, it has 32 bits of state and it gives the same sequence for
|
|
5
|
+
* the same seed on each platform. It is not for cryptography. Each repository that copied mulberry32
|
|
6
|
+
* gets the same numbers from `random(seed).next`, so a move to this package keeps the records equal.
|
|
7
|
+
*/
|
|
8
|
+
/** A source of uniform numbers from 0 (included) to 1 (not included). */
|
|
9
|
+
type Source = () => number;
|
|
10
|
+
/** The generator mulberry32. The seed is read as a 32-bit unsigned integer. */
|
|
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;
|
|
14
|
+
/** The 32-bit seed of a number (its low 32 bits, unsigned) or of a string (its FNV-1a hash). */
|
|
15
|
+
export declare function seedOf(seed: number | string): number;
|
|
16
|
+
/** The seed of the stream with the name `label` under `seed`: the hash of `"<seed>:<label>"`. */
|
|
17
|
+
export declare function deriveSeed(seed: number, label: string): number;
|
|
18
|
+
interface Random {
|
|
19
|
+
/** The 32-bit seed that the generator started with. Write it in each failure message, so a run can replay. */
|
|
20
|
+
readonly seed: number;
|
|
21
|
+
/** A uniform number from 0 (included) to 1 (not included). */
|
|
22
|
+
next(): number;
|
|
23
|
+
/** A uniform integer from `min` to `max`, both included. */
|
|
24
|
+
int(min: number, max: number): number;
|
|
25
|
+
/** A uniform integer from 0 (included) to `n` (not included). */
|
|
26
|
+
below(n: number): number;
|
|
27
|
+
/** A uniform number from `min` (included) to `max` (not included). */
|
|
28
|
+
range(min: number, max: number): number;
|
|
29
|
+
/** `true` with the probability `p`. */
|
|
30
|
+
chance(p: number): boolean;
|
|
31
|
+
/** One item of a list that is not empty, each with the same probability. */
|
|
32
|
+
pick<T>(items: readonly T[]): T;
|
|
33
|
+
/** The index of a weight, with a probability in proportion to the weight. One draw. */
|
|
34
|
+
weighted(weights: readonly number[]): number;
|
|
35
|
+
/** A new list with the items in a uniform random order (Fisher–Yates, from the end). */
|
|
36
|
+
shuffle<T>(items: readonly T[]): T[];
|
|
37
|
+
/** `k` different items of a list, in the order of the draw (a partial Fisher–Yates). */
|
|
38
|
+
sample<T>(items: readonly T[], k: number): T[];
|
|
39
|
+
/** A normal sample (Box–Muller, two draws). */
|
|
40
|
+
normal(mean?: number, sd?: number): number;
|
|
41
|
+
/** An independent generator for the part of the work with the name `label`. The same labels give the same streams. */
|
|
42
|
+
fork(label: string): Random;
|
|
43
|
+
}
|
|
44
|
+
/** A generator with draws, from a seed. The default source is mulberry32. */
|
|
45
|
+
export declare function random(seed: number | string, source?: (seed: number) => Source): Random;
|
|
46
|
+
/** A generator with draws, from a source that you give. `fork` uses `source` for the new streams. */
|
|
47
|
+
export declare function randomOf(next: Source, seed: number, source?: (seed: number) => Source): Random;
|
|
48
|
+
/**
|
|
49
|
+
* The seeds of a run: the seed in `given` (the text of an environment variable, for example
|
|
50
|
+
* `process.env.SEED`), else the default seeds. An empty text gives the defaults.
|
|
51
|
+
*/
|
|
52
|
+
export declare function seedsFrom(given: string | undefined, defaults: readonly number[]): number[];
|
|
53
|
+
export type { Random, Source };
|
|
54
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +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"}
|
package/build/index.js
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
// src/random.ts
|
|
2
|
+
/** The generator mulberry32. The seed is read as a 32-bit unsigned integer. */
|
|
3
|
+
function mulberry32(seed) {
|
|
4
|
+
let state = seed >>> 0;
|
|
5
|
+
return () => {
|
|
6
|
+
state = state + 1831565813 >>> 0;
|
|
7
|
+
let t = state;
|
|
8
|
+
t = Math.imul(t ^ t >>> 15, t | 1);
|
|
9
|
+
t ^= t + Math.imul(t ^ t >>> 7, t | 61);
|
|
10
|
+
return ((t ^ t >>> 14) >>> 0) / 4294967296;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
const UTF8 = new TextEncoder();
|
|
14
|
+
/** The FNV-1a hash of 32 bits of the UTF-8 bytes of a string. */
|
|
15
|
+
function fnv1a32(text) {
|
|
16
|
+
let h = 2166136261;
|
|
17
|
+
for (const b of UTF8.encode(text)) h = Math.imul(h ^ b, 16777619) >>> 0;
|
|
18
|
+
return h;
|
|
19
|
+
}
|
|
20
|
+
/** The 32-bit seed of a number (its low 32 bits, unsigned) or of a string (its FNV-1a hash). */
|
|
21
|
+
function seedOf(seed) {
|
|
22
|
+
if (typeof seed === "string") return fnv1a32(seed);
|
|
23
|
+
if (!Number.isFinite(seed)) throw new RangeError(`seedOf: a seed is a finite number or a string, not ${seed}.`);
|
|
24
|
+
return seed >>> 0;
|
|
25
|
+
}
|
|
26
|
+
/** The seed of the stream with the name `label` under `seed`: the hash of `"<seed>:<label>"`. */
|
|
27
|
+
function deriveSeed(seed, label) {
|
|
28
|
+
return fnv1a32(`${seed}:${label}`);
|
|
29
|
+
}
|
|
30
|
+
function wholeOrThrow(name, value) {
|
|
31
|
+
if (!Number.isSafeInteger(value)) throw new RangeError(`${name}: ${value} is not a safe integer.`);
|
|
32
|
+
}
|
|
33
|
+
/** A generator with draws, from a seed. The default source is mulberry32. */
|
|
34
|
+
function random(seed, source = mulberry32) {
|
|
35
|
+
const start = seedOf(seed);
|
|
36
|
+
return randomOf(source(start), start, source);
|
|
37
|
+
}
|
|
38
|
+
/** A generator with draws, from a source that you give. `fork` uses `source` for the new streams. */
|
|
39
|
+
function randomOf(next, seed, source = mulberry32) {
|
|
40
|
+
const below = (n) => {
|
|
41
|
+
wholeOrThrow("below", n);
|
|
42
|
+
if (n < 1) throw new RangeError(`below: n is 1 or more, not ${n}.`);
|
|
43
|
+
return Math.floor(next() * n);
|
|
44
|
+
};
|
|
45
|
+
return {
|
|
46
|
+
seed,
|
|
47
|
+
next,
|
|
48
|
+
int(min, max) {
|
|
49
|
+
wholeOrThrow("int", min);
|
|
50
|
+
wholeOrThrow("int", max);
|
|
51
|
+
if (min > max) throw new RangeError(`int: min ${min} is more than max ${max}.`);
|
|
52
|
+
return min + Math.floor(next() * (max - min + 1));
|
|
53
|
+
},
|
|
54
|
+
below,
|
|
55
|
+
range: (min, max) => min + next() * (max - min),
|
|
56
|
+
chance: (p) => next() < p,
|
|
57
|
+
pick(items) {
|
|
58
|
+
if (items.length === 0) throw new RangeError("pick: the list is empty.");
|
|
59
|
+
return items[below(items.length)];
|
|
60
|
+
},
|
|
61
|
+
weighted(weights) {
|
|
62
|
+
let total = 0;
|
|
63
|
+
for (const w of weights) {
|
|
64
|
+
if (!(Number.isFinite(w) && w >= 0)) throw new RangeError(`weighted: each weight is finite and 0 or more, not ${w}.`);
|
|
65
|
+
total += w;
|
|
66
|
+
}
|
|
67
|
+
if (!(total > 0)) throw new RangeError("weighted: the sum of the weights is 0.");
|
|
68
|
+
let left = next() * total;
|
|
69
|
+
for (let i = 0; i < weights.length; i++) {
|
|
70
|
+
left -= weights[i];
|
|
71
|
+
if (left < 0) return i;
|
|
72
|
+
}
|
|
73
|
+
for (let i = weights.length - 1;; i--) if (weights[i] > 0) return i;
|
|
74
|
+
},
|
|
75
|
+
shuffle(items) {
|
|
76
|
+
const out = [...items];
|
|
77
|
+
for (let i = out.length - 1; i > 0; i--) {
|
|
78
|
+
const j = below(i + 1);
|
|
79
|
+
[out[i], out[j]] = [out[j], out[i]];
|
|
80
|
+
}
|
|
81
|
+
return out;
|
|
82
|
+
},
|
|
83
|
+
sample(items, k) {
|
|
84
|
+
wholeOrThrow("sample", k);
|
|
85
|
+
if (k < 0 || k > items.length) throw new RangeError(`sample: k is from 0 to ${items.length}, not ${k}.`);
|
|
86
|
+
const out = [...items];
|
|
87
|
+
for (let i = 0; i < k; i++) {
|
|
88
|
+
const j = i + below(out.length - i);
|
|
89
|
+
[out[i], out[j]] = [out[j], out[i]];
|
|
90
|
+
}
|
|
91
|
+
return out.slice(0, k);
|
|
92
|
+
},
|
|
93
|
+
normal(mean = 0, sd = 1) {
|
|
94
|
+
const u1 = Math.max(next(), 1e-12);
|
|
95
|
+
const u2 = next();
|
|
96
|
+
return mean + sd * Math.sqrt(-2 * Math.log(u1)) * Math.cos(2 * Math.PI * u2);
|
|
97
|
+
},
|
|
98
|
+
fork(label) {
|
|
99
|
+
const child = deriveSeed(seed, label);
|
|
100
|
+
return randomOf(source(child), child, source);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* The seeds of a run: the seed in `given` (the text of an environment variable, for example
|
|
106
|
+
* `process.env.SEED`), else the default seeds. An empty text gives the defaults.
|
|
107
|
+
*/
|
|
108
|
+
function seedsFrom(given, defaults) {
|
|
109
|
+
if (given === void 0 || given.trim() === "") return [...defaults];
|
|
110
|
+
const seed = Number(given);
|
|
111
|
+
if (!Number.isSafeInteger(seed)) throw new RangeError(`seedsFrom: a seed is an integer, not ${given}.`);
|
|
112
|
+
return [seed];
|
|
113
|
+
}
|
|
114
|
+
export { deriveSeed, fnv1a32, mulberry32, random, randomOf, seedOf, seedsFrom };
|
|
115
|
+
|
|
116
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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,MA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G,OAAO,CAAC,IAAI;AACd"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,61 @@
|
|
|
1
1
|
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/package",
|
|
2
3
|
"name": "@mark1russell7/rigor-generators",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
4
|
+
"version": "0.1.0",
|
|
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
|
+
"keywords": [
|
|
7
|
+
"random",
|
|
8
|
+
"seed",
|
|
9
|
+
"seeded",
|
|
10
|
+
"prng",
|
|
11
|
+
"mulberry32",
|
|
12
|
+
"fnv1a",
|
|
13
|
+
"deterministic",
|
|
14
|
+
"testing",
|
|
15
|
+
"benchmark",
|
|
16
|
+
"fixtures"
|
|
17
|
+
],
|
|
18
|
+
"homepage": "https://github.com/mark1russell7/rigor/tree/main/packages/generators#readme",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/mark1russell7/rigor/issues"
|
|
21
|
+
},
|
|
22
|
+
"repository": {
|
|
23
|
+
"type": "git",
|
|
24
|
+
"url": "git+https://github.com/mark1russell7/rigor.git",
|
|
25
|
+
"directory": "packages/generators"
|
|
26
|
+
},
|
|
27
|
+
"license": "MIT",
|
|
28
|
+
"author": "Mark Russell (https://github.com/mark1russell7)",
|
|
29
|
+
"type": "module",
|
|
30
|
+
"main": "./build/index.js",
|
|
31
|
+
"files": [
|
|
32
|
+
"build"
|
|
33
|
+
],
|
|
34
|
+
"publishConfig": {
|
|
35
|
+
"access": "public"
|
|
36
|
+
},
|
|
37
|
+
"engines": {
|
|
38
|
+
"node": ">=22"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"@mark1russell7/cue": "^1.0.2",
|
|
42
|
+
"@types/node": "^26.6.5",
|
|
43
|
+
"tsdown": "^0.23.1",
|
|
44
|
+
"typescript": "^7.0.2",
|
|
45
|
+
"vitest": "^5.0.3"
|
|
46
|
+
},
|
|
47
|
+
"scripts": {
|
|
48
|
+
"build": "tsdown",
|
|
49
|
+
"test": "vitest run",
|
|
50
|
+
"test:watch": "vitest",
|
|
51
|
+
"typecheck": "tsc -p tsconfig.json && tsc -p tsconfig.test.json"
|
|
52
|
+
},
|
|
53
|
+
"types": "./build/index.d.ts",
|
|
54
|
+
"exports": {
|
|
55
|
+
".": {
|
|
56
|
+
"types": "./build/index.d.ts",
|
|
57
|
+
"import": "./build/index.js"
|
|
58
|
+
},
|
|
59
|
+
"./package.json": "./package.json"
|
|
60
|
+
}
|
|
6
61
|
}
|