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.
New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources