Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python multiple random seeds

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?

like image 951
Mohammad Amin Avatar asked May 11 '17 23:05

Mohammad Amin


1 Answers

You can use several different np.random.RandomStates 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.

like image 155
MSeifert Avatar answered Sep 21 '22 19:09

MSeifert