Alex Rivera | Logout

Python's random: What happens if I don't use seed(someValue)?

Asked 2009-05-03T18:44:19.067
22

a)In this case does the random number generator uses the system's clock (making the seed change) on each run?

b)Is the seed used to generate the pseudo-random values of expovariate(lambda)?

Edit
Report

1 Answer

18

"Use the Source, Luke!"...;-). Studying https://svn.python.org/projects/python/trunk/Lib/random.py will rapidly reassure you;-).

What happens when seed isn't set (that's the "i is None" case):

if a is None:
    try:
        a = long(_hexlify(_urandom(16)), 16)
    except NotImplementedError:
        import time
        a = long(time.time() * 256) # use fractional seconds

and the expovariate:

random = self.random
u = random()
while u <= 1e-7:
    u = random()
return -_log(u)/lambd

obviously uses the same underlying random generator as every other method, and so is identically affected by the seeding or lack thereof (really, how else would it have been done?-)

answered 2009-05-03T19:04:15.867

Your Answer