Re: /dev/random vs. /dev/urandom

From: Patrick J. LoPresti
Date: Mon Jan 10 2005 - 10:33:26 EST


linux-os <linux-os@xxxxxxxxxxxxxxxxxx> writes:

> In the first place, the problem was to display the error of using
> an ANDing operation to truncate a random number.

In the first place, you began by claiming that the number of zero bits
should equal the number of one bits. I explained how that was wrong,
and now you are saying you meant something else.

Fine, but you are still wrong; it is not an error to use AND.
/dev/random is just a stream of bits. Each bit behaves like a coin
toss. When you group the bits into bytes and then AND each byte with
1, you merely examine every eighth bit and throw away the rest. Each
bit you examine still behaves just like a coin toss.

So ANDing with 1 produces fine output if you are trying to simulate a
fair coin. Counter to your original claim, the output of your program
is completely consistent with the theory on this.

> In the limit, one could AND with 0 and show that all randomness has
> been removed.

Since that throws away ALL of the bits, of course it "removes the
randomness". Yes, each byte from /dev/random is a perfectly random
number between 0 and 255. If you AND with 1, you get a perfectly
random number between 0 and 1. If you AND with 0, you no longer get a
random number. Awesome!

> The short number of samples was DELIBERATELY used to exacerbate the
> problem although a number or nay-sayers jumped on this in an attempt
> to prove that I don't know what I'm talking about.

An impression you are reinforcing with every message. There is
nothing wrong with the randomness from /dev/random, nor with the
odd/even randomness in your sample program's output. Other than
"trust me", "try it with a real coin", or "read a book", I am not sure
how to convince you of this... So I will probably stop trying.

- Pat

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/