[Python-ideas] Globally configurable random number generation

Robert Kern robert.kern at gmail.com
Mon Sep 14 21:25:14 CEST 2015

On 2015-09-14 17:56, Sturla Molden wrote:
> On 14/09/15 17:50, Robert Kern wrote:
>> Actually, it's well behind the state of the art as it fails BigCrush.
>> The proposed alternative does better in this regard.
> Is that one of the PCGs? Or Arc4Random, ChaCha20 or XorShift64/32?

The alternative proposed in this thread is ChaCha20.

> The three latter fails on k-dimensional equi-distribution, MT does not. Some of
> the PCGs do too, but some should be as good as MT. Not sure if that is worse or
> better than failing some parts of BigCrush.

There is a reason that exact k-dimensional equidistribution for such a large k 
is not tested even in BigCrush. It's a nifty feature useful in a few 
applications, but not for simulations. It is important that the PRNG is 
*well*-distributed, but exact equidistribution is mostly neither here nor there. 
It can be trivially implemented by statistically bad PRNGs, like a simple 
counter. Obtaining it requires implementing an astronomically long period (and 
consequent growth in the state size) that adds significant costs without any 
realizable improvement to the statistics. If I'm drawing millions of numbers, 
k=623 is not much better than k=1, provided that the generator is otherwise good.

> Which PCG would you recommend, by the way?

Probably pcg64 (128-bit state, 64-bit output). Having the 64-bit output is nice 
so you only have to draw one value to make a uniform(0,1) double, and a period 
of 2**128 is nice and roomy without being excessively large.

Robert Kern

"I have come to believe that the whole world is an enigma, a harmless enigma
  that is made terrible by our own mad attempt to interpret it as though it had
  an underlying truth."
   -- Umberto Eco

More information about the Python-ideas mailing list