SeededRandom

Deterministic pseudorandom number generator using the Mulberry32 algorithm. Provides seeded repeatable random sequences for gameplay, procedural generation, and replay verification.

Constructor

new SeededRandom(seedopt)

Parameters:
NameTypeAttributesDefaultDescription
seednumber<optional>
1

Starting integer or float seed.

Classes

SeededRandom

Members

initialSeed :number

The original seed this instance was initialized or re-seeded with.

Type:
  • number

Methods

choice(array) → {T|undefined}

Select a random item from an array without modifying the array.

Parameters:
NameTypeDescription
arrayArray.<T>
Returns:
Type: 
T | undefined

getState() → {Object}

Snapshot current internal state for serialization / checkpoints.

Returns:
Type: 
Object

next() → {number}

Advance the generator and return a uniform float in [0, 1).

Returns:
Type: 
number

nextBool(chanceopt) → {boolean}

Return true with probability chance (defaults to 0.5 for a 50/50 flip).

Parameters:
NameTypeAttributesDefaultDescription
chancenumber<optional>
0.5
Returns:
Type: 
boolean

nextFloat(minopt, maxopt) → {number}

Return a uniform float in the range [min, max).

Parameters:
NameTypeAttributesDefaultDescription
minnumber<optional>
0
maxnumber<optional>
1
Returns:
Type: 
number

nextInt(min, max) → {number}

Return a uniform integer in the inclusive range [min, max].

Parameters:
NameTypeDescription
minnumber
maxnumber
Returns:
Type: 
number

setSeed(seed)

Re-seed the generator with a new seed value.

Parameters:
NameTypeDescription
seednumber

setState(snapshot)

Restore internal state from a previously saved snapshot.

Parameters:
NameTypeDescription
snapshotObject

State snapshot object containing numeric state.

Properties
NameTypeAttributesDescription
seednumber<optional>
statenumber

shuffle(array) → {Array.<T>}

In-place deterministic Fisher-Yates shuffle.

Parameters:
NameTypeDescription
arrayArray.<T>
Returns:
Type: 
Array.<T>