Python/ref random setstate
来自菜鸟教程
<languages />
Python Random setstate()方法
例
捕获并恢复随机数生成器的状态:
import random
#print a random number:
print(random.random())
#capture the state:
state = random.getstate()
#print another
random number:
print(random.random())
#restore the state:
random.setstate(state)
#and the next random number should be the same
as when you captured the state:
print(random.random())
定义和用法
The
setstate()
方法用于将随机数生成器的状态恢复到指定状态
使用
getstate()
捕获状态的方法
句法
random.setstate(state)
参数值
| 参数 | 描述 |
|---|---|
| state | 需要。状态对象。setstate()方法会将随机数生成器的状态恢复到此状态。 |