Member-only story

This article demonstrates how to use random.seed()
function to initialize the pseudo-random number generator in Python to get the deterministic random data you want. By setting the custom seed value we can get the determined sequence of random numbers.
Goals of this lesson. In this lesson you’ll learn how to:
- Use
random.seed()
to initialize the pseudo-random number generator. - Choose the same elements from the list randomly every time using
random.seed()
- Use a
random.seed()
function with other random module functions.
How to use random.seed() function
Let’s understand the working of a random module before proceeding further. The random number or data generated by Python’s random module is not truly random; it is pseudo-random(it is PRNG), i.e., deterministic. The random module uses the seed value as a base to generate a random number.
Syntax of random.seed()
random.seed(a, version)
Parameter
- a: Optional. The seed value needed to generate a random number.
If it is an integer it is used directly, if not it has to be converted into an integer. The default value is None, and if None, the generator uses the current…