logoalt Hacker News

pmarrecktoday at 1:02 AM0 repliesview on HN

I had issues with reproducing some fuzz testing failures in CI locally; turns out that glibc, musl and macOS actually DO NOT return the same floating point values for certain trig/transcendental functions across all OS'es, so I decided to rectify that by spelunking a deep rabbit hole: https://github.com/pmarreck/random

In order to make it work, I had to re-implement some math, so I avoided floating-point altogether (IEEE754 is a personal pet peeve) and went with mantissa and exponent fixed-point decimal. Or should I say binary, because the "decimal place" is the number of bits, not the number of base-10 decimal places.

Apparently this is the only deterministic, cross-platform, cryptographically-secure procedural RNG that has many types of distributions (uniform (default), normal (Box-Muller), exponential, Poisson, log-normal, beta... all with configurable inputs AND which will plot the distribution for you in the terminal!) AND is guaranteed to give you the same values... Everywhere. (Because how the fuck has this not existed yet??) Implemented in both LuaJIT and Zig with C FFI. So there you go. MIT license. Enjoy your deterministic but still very random numbers, on every OS, identically.

(It sources the best-in-class recommended source per OS if you want true random. It will do that too.)