New Lagged Fib. PRNG gen and random2.d

monarch_dodra monarchdodra at gmail.com
Mon Aug 26 02:24:56 PDT 2013


On Sunday, 25 August 2013 at 20:30:04 UTC, bearophile wrote:
> Before being merged into Phobos someone has to measure a bit 
> the actual quality of the random numbers it produces. To avoid 
> problems like the ones had with Xorshift. There are suites and 
> tools to measure the quality of random numbers, like a more 
> modern version of the famous diehard.

I can't comment on the quality of the PRNG itself, as I'm no RNG 
expert myself, but the code *was* ported from boost, and produces 
the same output. So arguably, we have matching quality.

On Sunday, 25 August 2013 at 20:30:04 UTC, bearophile wrote:
> What is its relative performance (measured with LDC2 and/or 
> GDC) compared to Xorshift and the Mersenne Twister when it is 
> used to generate integers and when it's used to generate 
> floating point numbers in 0..1 (for the floating point case you 
> have to use something like random01 to have a fair comparison)?

A valid question. I benched it, and the results are, IMO *very* 
good. The tests were run using the reference dmd 2.0.63.2, on a 
win7_64.

When generating uint's with 32 bits of randomness, I'm on par 
with MinstdRand0 in terms of speed, which is pretty good I think. 
It is faster than MT, but still slower than XS.

However, it can *also* generate ulongs with 64 bits of 
randomness, but doing so only takes roughly 40% more time. Which 
is great? I'd have to bench on a linux 64 with a dmd64 compiler: 
I think a true 64 bit implementation should have even less 
overhead, making LF *faster* (!) than MinstdRand0.

Another interesting bench was generating doubles: Lagged 
Fibonacci is able to natively generate doubles. As such, I 
benched it against the other generators, after dividing the 
output by Generator.max. This should be of interest to you...

The results are also good: I'm getting *slightly* slower times 
than MinstdRand0 (roughly 10% slower), but still faster than MT. 
HOWEVER, PRNG/PRNG.max will generate doubles with only 32 bits of 
significant fractional part. LF will generate doubles with either 
48 bits is significance (by default), or the full 52 bits. It is 
*also* able to generate reals with the full 64 bits of 
significant data, but this is somewhat slower. Awesome!

--------

That's my biased review/comment on the numbers. I'll post them 
here, so you can interpret yourself.


More information about the Digitalmars-d mailing list