I have a project with different main files (for different simulations). When I run one of the mainfiles, it should set a seed to random (and numpy.random), and all the modules in the project should use that seed.
I don't find a good way to do this. I have a file globals.py with this:
import random
myRandom=None
def initSeed(seed):
global myRandom
myRandom =random.Random(seed)
then from a main I do:
if __name__ == "__main__":
seed=10
globals.initSeed(seed)
...
Then in the modules that main calls, I do:
from globals import myRandom
But myRandom has the value None in the module (even though I modified it in main!). Why, and how to fix it? Is there a nicer way?
Aucun commentaire:
Enregistrer un commentaire