Home >>Python Random Module >Python Random setstate() Method

Python Random setstate() Method

Python Random setstate() Method

Python Random setstate() Method in python is used to restore the state to the specified state of the random number generator.

Syntax:
random.setstate(state)

Parameter Values

Parameter Description
state It is Required to restore the state of the random number generator.
Here is an example of Python Random setstate() Method:

import random
print(random.random())
state = random.getstate()
print(random.random())
random.setstate(state)
print(random.random())

Output:
0.6731178120498394
0.5642272440431916
0.5642272440431916
Example 2:

import random
print(random.random())

Output:
0.6571506327135164

No Sidebar ads