sam wolfe
sam wolfe

Reputation: 111

How to set random seeds globally?

I have observed that when I set the random seed using np.random.seed(seed) and then generate random numbers in a loop, as shown below:

import numpy as np

np.random.seed(4)
for i in range(3):
    print(np.random.uniform(0, 1, 4))

I get three different lists of random numbers. However, if I set the random seed within the loop, I obtain the same list of random numbers each time.

Is there a way to globally set the random seed such that it remains consistent even within loops? I want it so that any randomly generated points are generated according to the global seed.

Upvotes: 1

Views: 105

Answers (0)

Related Questions