set random seed programwide in python

In the beginning of your application call random.seed(x) making sure x is always the same. This will ensure the sequence of pseudo random numbers will be the same during each run of the application.


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.


zss's comment should be highlighted as an actual answer:

Another thing for people to be careful of: if you're using numpy.random, then you need to use numpy.random.seed() to set the seed. Using random.seed() will not set the seed for random numbers generated from numpy.random. This confused me for a while. -zss