random number generator thread safety

Paul Rubin http
Tue Nov 8 18:37:26 EST 2005


"Raymond Hettinger" <python at rcn.com> writes:
> Thread-safety has nothing to do with preserving entropy or guarding
> against attack.  All of the entropy in an MT sequence is contained in
> the seed (upto 624 bytes) and that entropy is preserved through all
> subsequent calls.

I think the concern is that there can be a thread switch after some
intermediate result is computed but before the state is updated.  That
would mean two threads can get random numbers that are identical or
anyway correlated.  Whether that can happen with Python's MT, I don't
know.

> Nothing in the random module provides cryptographic guarantees.  If you
> want crypto-strength, then use real encryption.  Search SourceForge for
> patches that show how to use MD5 and other cryptographic hash functions
> as a basis for random number generation.

Or use os.urandom.



More information about the Python-list mailing list