3 ms·
Cool observation! Despite knowing both about how floating points work and how random number generation works, this never occurred to me. I do wish the solution
by kevmo314 1y ago
Cool observation! Despite knowing both about how floating points work and how random number generation works, this never occurred to me.
I do wish the solution were a bit simpler though. Could this be upstreamed into the language's API? https://cs.opensource.google/go/go/+/refs/tags/go1.24.3:src/math/rand/rand.go;l=189 https://cs.opensource.google/go/go/+/refs/tags/go1.24.3:src/...
- lutusp 1y ago> Could this be upstreamed into the language's API? If a language is in use, and if people have written code that generates pseudorandom sequences based on an initial seed, then no -- bad idea. Some programs rely on the same pseudorandom sequence for a given seed, and may fail otherwise.
- wtallis 1y agoThat really depends on whether the language's standard library API specifies that implementations will use a particular random number generator, or merely specifies that the RNG will have certain properties. If you're going to depend on reproducible, portable RNG behavior you need to get those random numbers from an API that guarantees a particular algorithm.