طريقة Python Random 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. |