samedi 21 novembre 2015

Is it necessary to call seed() when using random in Python?

I was looking at the following code:

from random import choice

for val in range(10):
    a = ','.join(str(choice(range(20))) for idx in range(4))
    print a

And realized that I hadn't used seed(). I've been taught to seed the random number generator if you intend to generate different psuedo-random sequences.

I decided to run the code, expecting to the sequence repeated each time. But after several runs of the code, it appears to generate a different sequence each time.

  1. Is it really necessary to seed the Python random number generator? or...
  2. Is seed being called by default somewhere? or...
  3. Am I doing something wrong and/or don't understand what's happening?



Aucun commentaire:

Enregistrer un commentaire