Python seed()设置生成随机数时使用的整数起始值。在调用任何其他随机模块函数之前调用此函数。
seed ( [x] )
x - 这是下一个随机数的种子。如果省略,则生成下一个随机数需要系统时间。
此方法不返回任何值。
下面的示例显示了种子()方法的用法。
链接:https://www.learnfk.comhttps://www.learnfk.com/python/number-seed.html
来源:LearnFk无涯教程网
#!/usr/bin/python import random random.seed( 10 ) print "Random number with seed 10 : ", random.random() # 它将生成相同的随机数 random.seed( 10 ) print "Random number with seed 10 : ", random.random() # 它将生成相同的随机数 random.seed( 10 ) print "Random number with seed 10 : ", random.random()
当无涯教程运行上面的程序时,它产生以下输出-
Random number with seed 10 : 0.57140259469 Random number with seed 10 : 0.57140259469 Random number with seed 10 : 0.57140259469
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)
Spring Cloud 微服务项目实战 -〔姚秋辰(姚半仙)〕