@maruaudio/dsp/noise/newlib-rand reproduces newlib's rand(): the 64-bit linear congruential generator
next = next × 6364136223846793005 + 1 (mod 2^64)
rand = (next >> 32) & 0x7fffffff // 0 to NEWLIB_RAND_MAXwith newlib's power-on seed of 1 and srand(seed) storing the seed. The state is two u32 words advanced with 16-bit partial products: every intermediate is an exact integer below 2^53, with no BigInt or Math.imul.
Parameters
There are no parameter setters. initNewlibRand(seed = 1) and seedNewlibRand(state, seed) set the low word to seed >>> 0 and clear the high word.
Lifecycle
initNewlibRand or seedNewlibRand → newlibRandNext per draw. On the device every consumer shares one process-wide stream; here the stream is a state record that its owner shares between consumers in the upstream call order. Draws allocate nothing and do no I/O.
When to use it
Ported firmware that draws rand() and has to reproduce the device's random choices draw for draw, as the CHOMPI TEMPO granular delay and arpeggiator do without ever seeding it. For other seeded streams, the package's canonical transition is @maru/noise-xorshift32.
Limits
- Integer output only; mapping to audio is the caller's (the leaf playground demo scales it to ±0.2).
- The sequence depends on draw order, so consumers sharing one state must draw in the upstream order.