Python Náhodná metoda setstate().
Příklad
Zachyťte a obnovte stav generátoru náhodných čísel:
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())
Definice a použití
Metoda setstate()
se používá k obnovení stavu generátoru náhodných čísel zpět do zadaného stavu
Použijte getstate()
metodu k zachycení stavu
Syntax
random.setstate(state)
Hodnoty parametrů
Parameter | Description |
---|---|
state | Required. A state object. the setstate() method will restore the state of the random number generator back to this sate. |