@maruaudio/dsp/noise/xorshift32 is the canonical raw xorshift32 state transition and its mapping to a bipolar number. The transition is three shift-and-xor steps on an unsigned 32-bit word:
x ^= x << 13; x ^= x >>> 17; x ^= x << 5 (all as u32)
bipolar = x / 2^31 − 1 // [−1, 1), unroundedlet state = 2463534242
state = xorshift32NextU32(state)
const sample = rawU32ToBipolar(state)Parameters
There are no setters or state. The caller passes the 32-bit state to xorshift32NextU32 and keeps the returned value as the next state. XORSHIFT32_ALGORITHM_REVISION (1) names the transition contract.
Lifecycle
Stateless functions; the caller owns and persists the state. Nothing allocates or does I/O.
When to use it
A deterministic, repeatable noise or random stream inside a voice or effect: excitation noise, random impulses, seeded variation that renders the same on every target.
Limits
- No seed policy: state 0 stays 0 for ever. Callers such as
@maru/noise-colouredreplace a zero seed before the first step. - Inputs are coerced with
>>> 0: −1 acts as0xffffffff, 1.9 as 1, and NaN or infinity as 0. rawU32ToBipolaris unrounded; a caller that stores f32 rounds it.