The seed method of the random module
The seed method of the random module initializes or stores a specific random number. The method uses the current system time of the OS to generate random numbers. The seed method is applied before the random method. The optional parameter of the method is a number for initialization or a kind of marking of the generated number. Therefore, when the random method is applied repeatedly, the generated number does not change. If the parameter is left empty, a new number will be generated each time.
Syntax
import random
random.seed(number for marking)
Example
Let's initialize the number before generating it:
random.seed(5)
print(random.random())
Result of code execution:
0.6229016948897019
Let's repeat the derivation of our number:
random.seed(5)
print(random.random())
random.seed(5)
print(random.random())
The result will remain the same:
0.6229016948897019
0.6229016948897019
See also
-
method
randomof modulerandom,
which returns a pseudo-random number -
method
uniformof modulerandom,
which generates a pseudo-random real number from the range -
method
randintof modulerandom,
which generates a pseudo-random integer from a range -
method
randrangeof modulerandom,
which returns a random number from a range