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

前端 未结 3 1719
迷失自我
迷失自我 2020-12-06 16:30

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 valu

3条回答
  •  感情败类
    2020-12-06 16:49

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

提交回复
热议问题