Python Random setstate() Metodo
Esempio
Cattura e ripristina lo stato del generatore di numeri casuali:
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())
Definizione e utilizzo
Il setstate()
metodo viene utilizzato per ripristinare lo stato del generatore di numeri casuali allo stato specificato
Usa il getstate()
metodo per catturare lo stato
Sintassi
random.setstate(state)
Valori dei parametri
Parameter | Description |
---|---|
state | Required. A state object. the setstate() method will restore the state of the random number generator back to this sate. |