SeedSequence
Defined in: src/seed/sequence.ts:111
Turns one seed into as many independent, well-mixed seeds as you need.
Seeding parallel workers with 1, 2, 3 gives streams that can correlate, because nearby seeds are nearby states. Spawning from a sequence puts each worker somewhere unrelated, and the whole tree still replays from the one root seed.
Example
Section titled “Example”import { Random, SeedSequence } from "ransu";
const root = SeedSequence.from(42);const workers = root .spawn(4) .map((child) => new Random(child.generateState(4)));
workers[0].random(); // independent of workers[1]
// The same root always produces the same children.SeedSequence.from(42).spawn(4);Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new SeedSequence(
entropy,spawnKey?):SeedSequence
Defined in: src/seed/sequence.ts:116
Parameters
Section titled “Parameters”entropy
Section titled “entropy”Uint32Array
spawnKey?
Section titled “spawnKey?”Uint32Array = ...
Returns
Section titled “Returns”SeedSequence
Properties
Section titled “Properties”entropy
Section titled “entropy”
readonlyentropy:Uint32Array
Defined in: src/seed/sequence.ts:112
spawnKey
Section titled “spawnKey”
readonlyspawnKey:Uint32Array
Defined in: src/seed/sequence.ts:113
Methods
Section titled “Methods”generateState()
Section titled “generateState()”generateState(
words):Uint32Array
Defined in: src/seed/sequence.ts:147
Produce words 32-bit words of engine state.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”Uint32Array
spawn()
Section titled “spawn()”spawn(
n):SeedSequence[]
Defined in: src/seed/sequence.ts:159
Derive n independent child sequences. Successive calls keep counting, so
spawn(2) twice yields four distinct children.
Parameters
Section titled “Parameters”number
Returns
Section titled “Returns”SeedSequence[]
from()
Section titled “from()”
staticfrom(seed):SeedSequence
Defined in: src/seed/sequence.ts:124
Parameters
Section titled “Parameters”Returns
Section titled “Returns”SeedSequence