[Numpy-discussion] Random number generators.
Stephan Tolksdorf
st at sigmasquared.net
Sun Jun 4 15:21:08 CDT 2006
> MWC8222:
>
> nums/sec: 1.12e+08
>
> MT19937:
>
> nums/sec: 5.41e+07
> The times for 32 bit binaries is roughly the same. For generating large
> arrays of random numbers on 64 bit architectures it looks like MWC8222
> is a winner. So, the question is, is there a good way to make the rng
> selectable?
Although there are in general good reasons for having more than one
random number generator available (and testing one's code with more than
one generator), performance shouldn't be the deciding concern for
selecting one. The most important characteristic of a random number
generator are its distributional properties, e.g. how "uniform" and
"random" its generated numbers are. There's hardly any generator which
is faster than the Mersenne Twister _and_ has a better
equi-distribution. Actually, the MT is so fast that on modern processors
the contribution of the uniform number generator to most non-trivial
simulation code is negligible. See www.iro.umontreal.ca/~lecuyer/ for
good (mathematical) surveys on this topic.
If you really need that last inch of performance, you should seriously
think about outsourcing your inner simulation loop to C(++). And by the
way, there's a good chance that making the rng selectable has a negative
performance impact on random number generation (at least if the
generation is done through the same interface and the current
implementation is sufficiently optimized).
Regards,
Stephan
More information about the Numpy-discussion
mailing list