How to use the random getstate() method in Python

Overview

The random.getstate() method in Python is simply used to get the present or current state of the pseudo-random number generator.

Syntax

random.getstate()

Parameter value

The random.getstate() method does not take any parameter value.

Example

Let’s return the current state of the pseudo-random number generator.

import random
print(random.getstate())

Explanation

  • Line 1: we imported the random module.
  • Line 3: we printed the current state of our pseudo-random number generator using the random.getstate() method.

Free Resources