mercredi 21 octobre 2020

Random function prediction in Python

According to the documentation of Random library, assuming the developer does not provide any seed(None) the function uses the system current time as a seed(time.time()).

Unfortunately, it seems the output doe not reflects the documentation

print(random.randrange(1,10))
a=time.time()
.
.
.
.
random.seed(a)
print(random.randrange(1,10))

The code above produces 2 different outputs so assuming I use windows 10(for those who might think in the direction of urandom supplier) and Python 3 my questions are:

  1. Why the above code does not produces the same output
  2. When I tried to find the seed assignment part in Random.py I couldn't find anywhere time.time() assignment to Random.seed so ID someone can refers to that part I will be grateful



Aucun commentaire:

Enregistrer un commentaire