Método aleatorio setstate() de Python
Ejemplo
Captura y restaura el estado del generador de números aleatorios:
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())
Definición y uso
El setstate()
método se utiliza para restaurar el estado del generador de números aleatorios al estado especificado
Utilice el getstate()
método para capturar el estado.
Sintaxis
random.setstate(state)
Valores paramétricos
Parameter | Description |
---|---|
state | Required. A state object. the setstate() method will restore the state of the random number generator back to this sate. |