Bug 18596 – std.random.unpredictableSeed could use something better than MinstdRand0
Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P3
Component
phobos
Product
D
Version
D2
Platform
All
OS
All
Creation time
2018-03-12T09:51:09Z
Last change time
2018-03-22T22:49:33Z
Assigned to
No Owner
Creator
Nathan S.
Comments
Comment #0 by n8sh.secondary — 2018-03-12T09:51:09Z
Currently `std.random.unpredictableSeed` returns the result of a thread-local MinstdRand0 instance xor'd against the clock. MinstdRand0 is slow (due to integer division) and somewhat outdated. A particular weakness of using MinstdRand0 is that it is very likely that consecutive calls to `unpredictableSeed` will return numbers that are identical in the high bit, since MinstdRand0 only produces results in the range `1 .. 2 ^^ 31 - 1`. There are modern PRNG algorithms that have comparable state size to MinstdRand0 (64 bits or 32 bits) but are faster than MinstdRand0 and have output that scores better on randomness tests like BigCrush. On some platforms we can use functions like `arc4random` which incorporate system entropy and remove the need to roll our own entropy-gathering function to set an initial state for a PRNG.
Comment #1 by n8sh.secondary — 2018-03-15T15:58:28Z