performance of script to write very long lines of random chars

Oscar Benjamin oscar.j.benjamin at gmail.com
Thu Apr 11 08:05:45 EDT 2013


On 11 April 2013 11:50, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> On Thu, 11 Apr 2013 10:47:43 +0100, Oscar Benjamin wrote:
>
>> On 11 April 2013 08:47, Steven D'Aprano
>> <steve+comp.lang.python at pearwood.info> wrote:
>>
>>> One thing to be aware of: urandom may run out of entropy, and then it
>>> will slow down a lot. If you don't care about cryptographic randomness,
>>> you could use this instead:
>>
>> Reading this I'm realising that I don't really know what os.urandom is.
>> How exactly is it generating random numbers and what do you mean by it
>> running out of entropy?
>
> Some (most?) modern operating systems provide a cryptographically strong
> source of non-deterministic randomness. The non-deterministic part comes
> from external "stuff", which is called "entropy". Typical sources of
> entropy include network events, user key-presses, moving the mouse, and
> (presumably in machines with special hardware), even thermal noise in
> electrical components.

> Entropy is used and discarded, so urandom needs the OS to continually
> replenish the amount of entropy. Under normal circumstances, this it
> does, but if you grab lots of urandom output on a system which is
> otherwise quiet and not doing anything, it could run out.

Okay, so I understand what entropy is in the thermodynamic sense and
also in the mathematical (Shannon) sense but I'm still confused about
what it means that the OS is somehow storing entropy. Do you mean that
it is always maintaining a buffer of what it considers to be random
bytes that it slowly builds up from noise that is made accessible to
the OS from the hardware?


Oscar



More information about the Python-list mailing list