Truly random numbers

Paul Rubin http
Tue Feb 11 18:49:51 EST 2003


Luka Milkovic <Luka.Milkovic at public.srce.hr> 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', urandom.read (2))
     if n < 10000: 
        break




More information about the Python-list mailing list