Python里seed()函数

seed()函数的功功能是每次改变随机数生成器的种子,会改变下一次随机数模块生成的随机数。seed()方法在每次调用随机函数之前使用。

如果种子不变,那么随机函数生成的随机数相同,例如:

#!/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
原文地址:https://www.cnblogs.com/zz22--/p/7365768.html