[Python Wpg] Tested seed()

Dave Gabrielson dave at gabrielson.ca
Thu Jun 28 16:42:38 CEST 2007


Hmm... in the stock 2.4 python distribution, the random module is source code, 
which is always fun to look at.  :-)

It seems that seed() will use os.urandom(), if available, and will fallback to 
time.time() if that's not around.  It also seems like the module bootstraps 
itself with a class instance, which is how the module does self-seeding... 
which is almost always what you want (i.e., don't call seed(), it's already 
been done for you).  A reason you may want to call seed is: if you are 
developing a program that relies on randomly influenced (but still 
complicated) choices, and you wished to debug the non-random portion of the 
logic... In my experience, seed( 2 ) and the like will ALWAYS produce the 
same sequence of pseudo-random numbers, which is useful for testing 
(sometimes), be it in Pascal, C++ or Python.

--Dave .
(Currently working on pseudo-random meshing algorithms in python!)

On Thursday 28 June 2007 09:18, Sara Arenson wrote:
> If you pass nothing, i.e. just write seed(), it automatically uses system
> time.
>
> Sara


More information about the Winnipeg mailing list