www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 18596] New: std.random.unpredictableSeed could use something

https://issues.dlang.org/show_bug.cgi?id=18596

          Issue ID: 18596
           Summary: std.random.unpredictableSeed could use something
                    better than MinstdRand0
           Product: D
           Version: D2
          Hardware: All
               URL: http://dlang.org/
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P3
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: n8sh.secondary hotmail.com

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.

--
Mar 12 2018