I want to check if the randint
function is already seeded.
Should I manually seed it? If yes, how can I do that?
I want to check if the randint
function is already seeded.
Should I manually seed it? If yes, how can I do that?
There is no need to explicitly seed, unless you have very specific requirements. The internal Random()
instance is automatically seeded the first time you import the module.
From the module documentation:
The functions supplied by this module are actually bound methods of a hidden instance of the random.Random class.
and the Random.__init__()
:
class Random(_random.Random): # ... def __init__(self, x=None): # ... self.seed(x) # ... _inst = Random()
so the instance calls self.seed(None)
when the module is created. None
means 'best available source of a seed' (which may be time.time()
), see random.seed()
:
If a is omitted or
None
, the current system time is used (together with the PID of the process). If randomness sources are provided by the operating system, they are used instead of the system time (see theos.urandom()
function for details on availability).