Skip to content

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.

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);

new SeedSequence(entropy, spawnKey?): SeedSequence

Defined in: src/seed/sequence.ts:116

Uint32Array

Uint32Array = ...

SeedSequence

readonly entropy: Uint32Array

Defined in: src/seed/sequence.ts:112


readonly spawnKey: Uint32Array

Defined in: src/seed/sequence.ts:113

generateState(words): Uint32Array

Defined in: src/seed/sequence.ts:147

Produce words 32-bit words of engine state.

number

Uint32Array


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.

number

SeedSequence[]


static from(seed): SeedSequence

Defined in: src/seed/sequence.ts:124

Seed

SeedSequence