Truly random numbers

John La Rooy nospampls.jlr at
Wed Feb 12 02:57:17 CET 2003

On 11 Feb 2003 15:49:51 -0800
Paul Rubin <> wrote:

> Luka Milkovic <Luka.Milkovic at> writes:
> > I am making a one time pad encryption program, and I have a little
> > problem. I somehow managed to make a small client which connects to
> > Forumilabs Hotbits random number generator, and I can download the
> > numbers. But the problem I am facing is that the connection is not
> > secured, it is actually plain-text protocol, and anyone can sniffit. Does
> > anyone have an idea how to solve this problem?
> Use an SSL tunnel and hope that Fourmilabs isn't logging the random
> numbers?
> > The second problem is much more important than the first... I don't know
> > how to obtain random numbers from /dev/random and since it is going to be
> > linux only application, I really need this as the source of my
> > entropy/random numbers. I was thinking that maybe I need to get data from
> > it, convert it into binary and then do it what ever I want. Anyway, what
> > I need is a list of n groups of XXXX ( four digits ) numbers, and I
> > solved it through the list, but can I ( I know I can, but I don't know
> > how ) somehow generate this list from /dev/random?
> First of all you should use /dev/urandom rather than /dev/random,
> since /dev/random can block if it runs out of system entropy.
> The simplest way to get a random 4 digit number from /dev/urandom
> is something like:
>    urandom = open("/dev/urandom")
>    while 1:
>      n = struct.unpack('H', (2))
>      if n < 10000: 
>         break

I don't think Luka wants pseudorandom numbers. To use /dev/random you can either
open it in nonblocking mode...

    import os"/dev/random",os.O_NONBLOCK)
    while 1:,1)     ### this will cause an exception if there is nothing to read

...or use select/poll

    import os,select



    while len(groups) < number_of_groups:
        while len(group) < length_of_group:
            if P.poll(0.1):
    print groups


More information about the Python-list mailing list