[Tutor] Sum of Scores

Tiger12506 keridee at jayco.net
Fri Jul 27 03:36:15 CEST 2007


> bhaaluu wrote:
>> Greetings,
>>
>> Beautiful! Thank you SO much for all the variations.
>> I'm so sure I'll have much to learn from them. This
>> is exactly the kind of stuff I'm currently studying.

I assume this is for me. Thank you kindly! :-)

>> I have a question for the list.
>> After I posted my snippet, I added time to import,
>> and a time.sleep(1) line to the code. The reason
>> I did this is because I'm under the (possibly mistaken?)
>> impression that random uses the computer
>> time as a random number generator 'seed',
>> for generating pseudo-random numbers?
>>
> It uses time, it may also use other things.
> However, this is only to initialize the random number generator.
> You only need one seed and from that you can generate an infinitely long
> string of pseudo-random numbers.

Not infinitely long. From the docs -

[Quote]
Almost all module functions depend on the basic function random(), which 
generates a random float uniformly in the semi-open range [0.0, 1.0). Python 
uses the Mersenne Twister as the core generator. It produces 53-bit 
precision floats and has a period of 2**19937-1. The underlying 
implementation in C is both fast and threadsafe. The Mersenne Twister is one 
of the most extensively tested random number generators in existence. 
However, being completely deterministic, it is not suitable for all 
purposes, and is completely unsuitable for cryptographic purposes.
[/Quote]

So only if you use the random functions
4.3154247973881626480552355163379e+6001
times would the pattern repeat itself. Until then, you're safe. ;-)

> In other words, the only way you'd end up getting the same value is if
> you ran the program, quit it, then ran it again, in less than a second.
> (or possibly reloaded the module)

This freaked me out for a bit with a c program I wrote a while back. It was 
a screen saver built upon random values. I would double click its icon, and 
accidently jerk the mouse, double click it again. I thought I noticed that 
the two screens were the same. A little research brought me to that tidbit 
of information.

I'm not sure if reloading the module would or not. I would think that the 
seeding of the generator would occur at import of the random module. In 
which case, it would only happen once because import modules are not 
imported twice in the same session. (see recent threads)

> But you can call the random functions in your code as often as you want
> safely.
>> Perhaps this is a question for the 'language lawyers'?
>>
> Not sure what this means.

I believe it means 'those who know the language inside and out' like a 
lawyer must know the law.

JS 



More information about the Tutor mailing list