user592419
user592419

Reputation: 5233

Does the seed function in numpy and random work need to be set in every module?

I am calling

np.random.seed(seed)
random.seed(seed)

in the __main__ module foo.py. That module calls out to another module bar.py that also uses results from np.random and random. Does the latter also need to set the seed?

Upvotes: 0

Views: 63

Answers (1)

wim
wim

Reputation: 362836

No. Using np.random.seed(...) sets a global random state.

Usually this is not desirable. You may prefer to use a np.random.RandomState() instance in your code, so that you don't also seed the PRNGs for all other library code within your runtime.

Upvotes: 2

Related Questions