goldensun 通过本文主要向大家介绍了python random.seed,python seed,python seed函数,python中seed,grapeseed服用方法等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
seed() 设置生成随机数用的整数起始值。调用任何其他random模块函数之前调用这个函数。
语法
以下是seed()方法的语法:
seed ( [x] )</div>
注意:此函数是无法直接访问的,所以需要导入seed模块,然后需要使用random静态对象来调用这个函数。
参数
- x -- 这是下一个随机数的种子。如果省略,则需要系统时间,以产生下一个随机数。
返回值
此方法不返回任何值。
例子
下面的例子显示了seed()方法的使用。
#!/usr/bin/python import random random.seed( 10 ) print "Random number with seed 10 : ", random.random() # It will generate same random number random.seed( 10 ) print "Random number with seed 10 : ", random.random() # It will generate same random number random.seed( 10 ) print "Random number with seed 10 : ", random.random()</div>
当我们运行上面的程序,它会产生以下结果:
Random number with seed 10 : 0.57140259469 Random number with seed 10 : 0.57140259469 Random number with seed 10 : 0.57140259469</div> </div>

