My question is related to What is the scope of a random seed in Python? . In the case of above question, it is clarified that there is a (hidden) global Random()
instance in the module for random
.
1) I would like to clarify, whether setting the random seed in one module will cause this to be the random seed in other modules and whether there are certain things to be aware of.
For instance: Given: moduleA.py, moduleB.py
moduleA.py:
import random
import moduleB
random.seed(my_seed)
moduleB.randomfct()
moduleB.py:
import random
def randomfct():
#do_things_using_random
Does moduleB also use my_seed
, or do I have to pass the seed to moduleB.py and set it again?
2) Does the order of setting the random seed / importing play any role? moduleA.py:
import random
random.seed(my_seed)
import moduleB
3) Is this also the case for setting numpy random seeds, e.g. np.random.seed(42)
?
Aucun commentaire:
Enregistrer un commentaire