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())
定義と使用法
このsetstate()
メソッドは、乱数ジェネレーターの状態を指定された状態に復元するために使用されます
メソッドを使用しgetstate()
て状態をキャプチャします
構文
random.setstate(state)
パラメータ値
Parameter | Description |
---|---|
state | Required. A state object. the setstate() method will restore the state of the random number generator back to this sate. |