splitmix32(
seed): () =>number
Defined in: packages/prng/src/splitmix32.ts:28
Creates a deterministic 32-bit pseudorandom number generator.
Each call advances a private state by 0x9e3779b9. This constant equals
floor(2^32 / phi), where phi is the golden ratio. Addition wraps modulo
2^32. Because the increment is odd, it is coprime to 2^32. The resulting
Weyl sequence visits every 32-bit state once before it repeats.
The mixing function uses the constants 0x21f0aaad and 0x735a2d97 from
the hash-prospector search
for low avalanche bias. Its XOR-shifts and multiplications by odd integers
are invertible over 32-bit values. The mixer therefore preserves the full
period while diffusing nearby states across the output bits.
Math.imul and the bitwise operators keep the mixing steps in 32-bit
arithmetic. The final unsigned conversion produces an integer from 0 to
2^32 - 1. Dividing by 2^32 maps that integer to [0, 1).
The SplitMix family was introduced by Steele, Lea, and Flood in Fast Splittable Pseudorandom Number Generators.
This generator is not cryptographically secure. Use crypto.getRandomValues()
when unpredictability matters.
Parameters
Section titled “Parameters”number
Initial seed, coerced to a signed 32-bit integer.
Returns
Section titled “Returns”A stateful function that returns the next value in the range [0, 1).
() => number