RE: /dev/random vs. /dev/urandom

David Schwartz
2005-01-10T19:46:20Z

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

Except there is no error.

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

Of course. Any time you truncate something, you are removing something from
it.

> However, those who know nothing about the theory would then
> probably jump upon this as a "special case" even though it usn't.

Nope, no special case. Truncate all the way, remove everything. Truncate
part of the way, remove something.

If you have a random number between 0 and 32767, and you want a random
number between 0 and 255, you are going to have to remove some of the
randomness from the input number. So long as the input random numbers are
uniform and the truncation maps the same number of inputs to each output,
any truncation scheme is as good as any other. Specifically, ANDing is as
good as dividing, is as good as any other scheme as far as the quality of
the output is concerned.

Where things get complicated is where the number of possible outputs does
not divide evenly into the number of possible inputs. For example,
truncating a random number between 0 and 32767 to one between 0 and 9. There
are some algorithms to do this, but ANDing is insufficient.

DS