Python สุ่มsetstate ()เมธอด
ตัวอย่าง
จับและกู้คืนสถานะของตัวสร้างตัวเลขสุ่ม:
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())
ความหมายและการใช้งาน
วิธี การsetstate()
นี้ใช้เพื่อกู้คืนสถานะของตัวสร้างตัวเลขสุ่มกลับเป็นสถานะที่ระบุ
ใช้getstate()
วิธีการยึดรัฐ
ไวยากรณ์
random.setstate(state)
ค่าพารามิเตอร์
Parameter | Description |
---|---|
state | Required. A state object. the setstate() method will restore the state of the random number generator back to this sate. |