[Tutor] printing the random seed?
Danny Yoo
dyoo at hkn.eecs.berkeley.edu
Thu Feb 2 08:16:50 CET 2006
> I am having some fun with python and making multiple runs on an
> algorhythm and sometimes getting some fun stuff that i would like to be
> able to reproduce, but there are some random elements in it. I wonder is
> there a way to see the random seed, and make note of it so that you
> could then set the seed for a subsequent run to get the same (initially)
> random results?
Hi Kevin,
Sure; take a look at the seed() function in the random module.
http://www.python.org/doc/lib/module-random.html#l2h-1298
Just set it to some consistant value at the very beginning of your
program, and you should then see duplicate results between program runs.
You could also probably do something with random.getstate() and
random.setstate(), but it's probably a bit simpler just to inject a known
seed value into the pseudorandom generator.
> (Hi Danny, if you are still here!)
*wave wave*
Good luck!
More information about the Tutor
mailing list