views:

1001

answers:

3

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)?

+3  A: 

a) It typically uses the system clock, the clock on some systems may only have ms precision and so seed twice very quickly may result in the same value.

seed(self, a=None) Initialize internal state from hashable object.

None or no argument seeds from current time or from an operating
system specific randomness source if available.

http://pydoc.org/2.5.1/random.html#Random-seed

b) I would imagine expovariate does, but I can't find any proof. It would be silly if it didn't.

e5
+1  A: 

current system time is used; current system time is also used to initialize the generator when the module is first imported. If randomness sources are provided by the operating system, they are used instead of the system time (see the os.urandom() function for details on availability).

Random Docs

Raisins
+4  A: 

"Use the Source, Luke!"...;-). Studying http://svn.python.org/view/python/trunk/Lib/random.py?revision=68378&view=markup 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?-)

Alex Martelli