set random seed programwide in python

Mischa Obrecht picture Mischa Obrecht · Jul 17, 2012 · Viewed 83.7k times · Source

I have a rather big program, where I use functions from the random module in different files. I would like to be able to set the random seed once, at one place, to make the program always return the same results. Can that even be achieved in python?

Answer

Jon Clements picture Jon Clements · Jul 17, 2012

The main python module that is run should import random and call random.seed(n) - this is shared between all other imports of random as long as somewhere else doesn't reset the seed.