Created
December 27, 2018 14:03
-
-
Save sparkydogX/08fd2a7f21775cb913c26216f6c5a869 to your computer and use it in GitHub Desktop.
在一个文件中控制不同的变量拥有不同的随机数种子
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
class rint(object): | |
def __init__(self,stat='A'): | |
self.val = 0 | |
if stat == 'train': | |
self.rng = np.random.RandomState(seed=100) | |
else: | |
self.rng = np.random.RandomState(seed=None) | |
def getval(self): | |
return self.rng.randint(10) | |
if __name__ == '__main__': | |
x=rint(stat='A') | |
y=rint(stat='B') | |
print(x.getval()) | |
print(y.getval()) | |
print(x.getval()) | |
print(y.getval()) | |
print(x.getval()) | |
print(y.getval()) | |
print(x.getval()) | |
print(y.getval()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment