SHA-based subclass for random module

Tim Peters tim.one at comcast.net
Mon Mar 22 13:41:46 EST 2004


[David MacQuigg]
> ...
> I'm still curious as to the answer to my very simple and basic
> question:

It is basic, but there's nothing simple about it.

> Are there any examples that show a *non-subjective* difference in a
> physically meaningful result between one PRNG and another?

Yes, but different RNGs have different weaknesses, and whether the
weaknesses of a specific RNG *matter* to you depend on detailed analysis of
the specific app you have in mind.

The primary weakness of linear congruential generators (still the most
common kind) is dramatically illustrated all over the web; e.g., look at the
3D plot at:

    http://www.unf.edu/ccec/cis/CIShtml/RANDUinfo.html

If you need to generate "random" points in 3D space, does it matter that the
particular LCG plotted there systematically generates points that fall on
one of 15 planes, no matter how many points you generate?  There's no answer
to that short of analyzing the specifics of what you're trying to accomplish
by generating those points.  For example, if your app relies on the triples
generated being approximately equally distributed throughout a 3D cube, that
particular LCG is an obvious disaster for that particular application.  But
if your app only cares that the projection of the points onto the x axis is
approximately equally distributed, probably no problem, despite that it's
obvious "by eyeball" that there's nothing even remotely "random" about their
distribution in 3D space.

You're not going to get an easy answer.  Well, here's one:  the Mersenne
Twister in Python 2.3 is probably the best and most widely tested fast PRNG
in existence now, and has provably good equidistribution properties in high
dimensions (a plot like the one above would have no visible patterns if the
Twister had been used instead).





More information about the Python-list mailing list