-1

I want to check if the randint function is already seeded.

Should I manually seed it? If yes, how can I do that?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Said Saifi
  • 1,995
  • 7
  • 26
  • 45

1 Answers1

7

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 the os.urandom() function for details on availability).

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343