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

Patrick J. LoPresti
2005-01-10T15:32:06Z

linux-os <linux-os@chaos.analogic.com> 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