Python Random setstate() Metode
Voorbeeld
Vang en herstel die toestand van die ewekansige getalgenerator:
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())
Definisie en gebruik
Die setstate()
metode word gebruik om die toestand van die ewekansige getalgenerator terug te herstel na die gespesifiseerde toestand
Gebruik die getstate()
metode om die staat vas te vang
Sintaksis
random.setstate(state)
Parameterwaardes
Parameter | Description |
---|---|
state | Required. A state object. the setstate() method will restore the state of the random number generator back to this sate. |