Reputation: 454
Is there any way to use two different seeds for numpy random number generator in a python code, one to be used for part of the code, and the other for the rest of the code?
Upvotes: 6
Views: 5534
Reputation: 152597
You can use several different np.random.RandomState
s and call the methods on those:
import numpy as np
rng1 = np.random.RandomState(100)
rng2 = np.random.RandomState(100)
print(rng1.randint(0, 100, 1)) # [8]
print(rng2.randint(0, 100, 1)) # [8]
I used the same seed (100
) for both, because it shows that both give the same results.
Upvotes: 20