6

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?
Jesuisme
  • 1,805
  • 1
  • 31
  • 41
  • 2
    Python 2.x docs state that simply importing the module seeds the RNG. IDK why Python 3.x docs removed that bit, but it still seems to be true. – Dúthomhas Nov 21 '15 at 23:47

1 Answers1

4

I think seed is just meant to be used

1) so that you can get the same predictable sequence every time if you seed with the same number

2) to feed a better (eg hardware generated) random number in as a start value

user2692263
  • 475
  • 4
  • 8