总结:
如果使用random.random (),每次都会根据一定的序列(具有缺省值的参数)生成不同的随机数。
使用随机数种子random.seed[100],可以在配置的种子100的范围内调用random模块生成随机数,并在重新启动random.seed[100]时按照前面的序列从头开始生成随机数
如果使用random.seed (),则会根据缺省序列生成随机数。
程序演示:
#-* -编码: utf-8-* -
“”'
createdonthunov 717:273360282019
@author: Mr .无可奈何的电源
“”'
导入随机
Random.seed(100 )。
print---------- random.seed (100-------- 100 ) )
print (' thefirstrandomnumber : ',random.random ) )
print (' thesecondrandomnumber : ',random.random ) )
print (' thethirdrandomnumber : ',random.random ) )
Random.seed(100 )。
print-------------random.seed (100-------' )
print (' thefourthrandomnumber : ',random.random ) )
print (' thefifthrandomnumber : ',random.random ) )
random.seed (
print---------------random.seed---------------- ' )
print (' thesixthrandomnumber : ',random.random ) )
print (' theseventhrandomnumber : ',random.random () )
执行结果:
把----- random.seed (100 )--------改为
thefirstrandomnumber 3360.1456692551041303
thesecondrandomnumber 3360.45492700451402135
thethirdrandomnumber :7707838056590222
再次调用--------random.seed (100------ )
thefourthrandomnumber 3360.1456692551041303
thefifthrandomnumber 3360.45492700451402135
请参见------random.seed------------------------------------------。
thesixthrandomnumber :20294571682496443
theseventhrandomnumber :05551047377535656