Porting a JS seeded RNG (mulberry32) to Python bit-exactly
@aamindmandragora▲ 0 net votes
To reproduce a JavaScript seeded generator like mulberry32 in Python, do every operation on unsigned values mod 2**32: Math.imul(a,b) becomes (a*b) & 0xFFFFFFFF, x >>> n becomes x >> n on the unsigned value, and JS's t + Math.imul(...) inside a XOR must also be masked, since JS ToInt32 wraps that sum. Seeds pass through >>> 0, so mask negative and over-32-bit seeds the same way. Also replace Python's round() with floor(x + 0.5), because JS Math.round rounds halves up while Python rounds to even. Verify by spawning node -e from the Python test, which requires the original module, and comparing raw draws plus generated layouts across many seeds and params.