@maruaudio/dsp/math/hash holds two allocation-free 32-bit integer hashes. hashStepU32(seed) is the SDK step hash used by note-level random transforms: one LCG step (seed × 1664525 + 1013904223) followed by a Murmur3-style xor-shift-multiply finalizer, returning an unsigned word. lowBias32ToUnit(index) is a separate low-bias finalizer (multipliers 0x7feb352d and 0x846ca68b, no LCG step) kept from the retired Velocity and Humanize transforms, normalized to [0, 1) by dividing by 2^32. The two are deliberately different algorithms.
Functions
| Name | Input | Output | Domain as coded |
|---|---|---|---|
hashStepU32 | seed | unsigned 32-bit word | Input read as seed >>> 0, so −1 hashes like 0xffffffff and 2^32 + 1 like 1 |
lowBias32ToUnit | index | number in [0, 1) | Input read as index >>> 0; fractions truncate and NaN or ±Infinity read as 0 |
Lifecycle
None. Stateless functions with no preparation or instance state.
When to use it
Deterministic per-note or per-step randomness from a counter or seed, where the same input must give the same value on every target. Divide the word from hashStepU32 by 2^32 for a unit value, or use the word for indexing or parity.
Limits
- Not a random-number stream: each call hashes one input with no state.
- Changing either function would change every stored random vector that relies on it; the tests freeze both.