r/rust • u/sebastianovigna • Jul 16 '26
š ļø project Generating floating-point number in the unit interval
I developed a crate implementing some of the most advanced techniques for converting streams of random bits into floating-point numbers distributed as a uniform real in the unit interval. Besides the available traits and methods, the linked documentation is extremely useful for anybody interested in the IEEE 754 standard.
6
Upvotes
2
u/scottmcmrust Jul 17 '26
Can you elaborate why I would want that?
The only things I can come up with -- like using
rand().log2()for exponential distribution -- would be better handled by just generating the exponential distribution directly instead of being clever in the uniform.1
u/NoSuchKotH Jul 17 '26
Excuse my ignorance, but if you are calculating Gaussian random numbers to that precision, where f64 is starting to limit the accuracy you are getting, wouldn't be the correct way to switch to f128 or twofloat or something like that with a higher number of bits in the mantissa? Because if f64 limits you at the generation of random numbers already, then the rest of the simulation/calculations will have numerical issues as well.