The seed is based on the clock or (if available) the source of the operating system. The random module creates (and therefore seeds) a common random instance when it is imported, and not the first time it is used.
References
Python docs for random.seed :
random.seed(a=None, version=2)
Initialize the random number generator.
If a is omitted or None, the current system time is used. If sources of randomness are provided by the operating system, they are used instead of system time (see the os.urandom () function for details on availability).
Source random.py (heavily cut off):
from os import urandom as _urandom class Random(_random.Random): def __init__(self, x=None): self.seed(x) def seed(self, a=None, version=2): if a is None: try: a = int.from_bytes(_urandom(32), 'big') except NotImplementedError: import time a = int(time.time() * 256)
The last line is at the top level, so it runs when the module loads.
source share