dimanche 1 septembre 2019

Why does the Python random.random() give a different value if the previously generated value is explicitly set as the new seed?

I have read that the random module in Python uses the previously generated value as the seed except for the first time where it uses the system time. If this is true, why don't I get the same value when I explicitly set the previously generated value as the new seed like this:

random.seed(random.randint(1, 100))

The same doesn't work for the random.random() method either.

>>> import random
>>> random.seed(20)
>>> random.randint(1,100)
93
>>> random.randint(1,100)
88
>>> random.seed(20)
>>> random.randint(1,100)
93
>>> random.randint(1,100)
88
>>> random.seed(20)
>>> random.seed(random.randint(1,100))
>>> random.randint(1,100)
64

Why didn't the last randint() call not give 88?

Thanks in Advance!




Aucun commentaire:

Enregistrer un commentaire