[Python-Dev] Unittests

Guido van Rossum guido@python.org
Tue, 09 Apr 2002 19:26:09 -0400


> What is the "Official Python(tm)" method for generating a
> "guaranteed for all time to always be the same if started with the
> same seed" string of random numbers for use in something like a
> UnitTest?

That's a good use case, although the WH algorithm is so simple that it
would probably be easier to isolate yourself from evolution of the
library by recoding it in that's really what you want.

> The Random module does not seem to make any promises about repeatability
> between versions, releases, operating-systems, etc.  The only thing which
> enforces the repeatability is the fact that the generator is actually the
> whrandom generator under the covers.
> 
> Incidentally, a similar question has been asked before and didn't really
> get good closure on the response, see:
> 
> http://groups.google.com/groups?hl=en&threadm=MPG.16a822cc6abaa77c98970e%40enews.newsguy.com&rnum=1&prev=/groups%3Fq%3Ddanil%2Bwhrandom%26hl%3Den%26selm%3DMPG.16a822cc6abaa77c98970e%2540enews.newsguy.com%26rnum%3D1

Tim didn't ask me before he responded; I might have suggested that
deprecating whrandom was a bit premature given your use case.  I can
certainly see the use of providing a given random algorithm for those
who want stability, while at the same time letting the random module
migrate to a stronger algorithm for the benefit for humanity.

But then again, Tim might have a good reason why that's a bad idea.  I
don't know.

--Guido van Rossum (home page: http://www.python.org/~guido/)