每次运行代码时**设置相同的seed,**则每次生成的随机数也相同,如果不设置seed,则每次生成的随机数都会不一样。
from numpy import *
num=0
while(num<5):
random.seed(5)
print(random.random())
num+=1
out:0.22199317108973948
0.22199317108973948
0.22199317108973948
0.22199317108973948
0.22199317108973948
from numpy import *
num=0
random.seed(5)
while(num<5):
print(random.random())
num+=1
out:0.22199317108973948
0.8707323061773764
0.20671915533942642
0.9186109079379216
0.48841118879482914