Python Random setstate() Metode
Contoh
Tangkap dan pulihkan status generator nomor acak:
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())
Definisi dan Penggunaan
Metode setstate()
ini digunakan untuk mengembalikan keadaan generator nomor acak kembali ke keadaan yang ditentukan
Gunakan getstate()
metode untuk menangkap keadaan
Sintaksis
random.setstate(state)
Nilai Parameter
Parameter | Description |
---|---|
state | Required. A state object. the setstate() method will restore the state of the random number generator back to this sate. |