Случайный Python: Что происходит, если я не использую семя (someValue)?

Не уверен относительно вашего точного вопроса, но попробуйте использовать StreamReader из System.IO, это довольно просто и прямо.

17
задан andandandand 3 May 2009 в 18:44
поделиться

3 ответа

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

17
ответ дан 30 November 2019 в 13:13
поделиться

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.

6
ответ дан 30 November 2019 в 13:13
поделиться

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

2
ответ дан 30 November 2019 в 13:13
поделиться
Другие вопросы по тегам:

Похожие вопросы: