首页 > 编程知识 正文

python中随机种子数,产生随机数种子

时间:2023-05-04 20:35:51 阅读:177633 作者:1651

总结:

如果使用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

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。