Puzzled about random initialisation
Robin Becker
robin at reportlab.com
Fri Jul 9 05:36:46 EDT 2004
Tim Peters wrote:
> [Robin Becker]
>
>>We've been queried about the randomness of some filenames we're producing.
>>I worked through and seemed to satisfy myself that random is being initialised
>>from the system time in C
>> time(&now)
>> init_genrand(self, (unsigned long)now);
>>
>>where now is a time expressed in integral seconds since the eopoch.
>
>
..... good stuff elided
> 641 unique random() values in 165923 attempts
> 641 unique time.time() values
>
> Since it ran for 10 seconds, I'm seeing time.time() change about 64
> times per second. I believe that's because this is a hyper-threaded
> box, Whatever, if I had been able to start ~166000 instance of Python
> in that time, I would have seen only ~640 different seedings across
> them.
thanks for all this it makes things a lot clearer. Using time.time() makes it
harder, but still not impossible to guess what values could have been generated.
The application should probably be using /dev/urandom to seed generators.
--
Robin Becker
More information about the Python-list
mailing list