[Tutor] What are these things urandom() returns?

Tim Peters tim.peters at gmail.com
Thu Oct 12 03:39:30 CEST 2006


[Tim Peters]
>> If you want /true/ randomness, you can buy a certified hardware random
>> number generator, based on non-deterministic physical processes (like
>> timing radioactive decay, or measuring thermal noise).

[Terry Carroll]
> Why buy when you can borrow?:

Speed and capacity, for two things ;-)  As the HotBits page says,
their method can't create more than about 100 bytes per second.  So
even if they were willing (which they aren't) to satisfy a request for
1000000 random bytes (as Dick used in one of his programs), it would
take close to 3 hours to get them.  Worse, many applications consume
1000s of times more than a measly million random bytes.

> def truerandom(n):
>     """
>     truerandom(n) --> str
>
>     Return a string of n truly random bytes.
>
>     see:
>       http://www.fourmilab.ch/hotbits/
>       http://www.fourmilab.ch/hotbits/generate.html
>
>     """
>
>     import urllib
>     _url = "http://www.fourmilab.ch/cgi-bin/Hotbits?nbytes=%s&fmt=bin" % n
>     return urllib.urlopen(_url).read()

Note that a reasonable use for this service is to request a "small"
number of random bytes to /seed/ a fast deterministic generator.


More information about the Tutor mailing list