Red Hat Bugzilla – Bug 228662
rand man page gives out-of-date advice
Last modified: 2007-11-30 17:11:57 EST
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:220.127.116.11) Gecko/20070131 Fedora/18.104.22.168-2.fc6 Firefox/22.214.171.124 pango-text
Description of problem:
The rand man page NOTES section says this:
"In Numerical Recipes in C: The Art of Scientific Computing
(William H. Press, Brian P. Flannery, Saul A. Teukolsky,
William T. Vetterling; New York: Cambridge University Press,
1992 (2nd ed., p. 277)), the following comments are made:
"If you want to generate a random integer between 1
and 10, you should always do it by using high-order
bits, as in
j = 1 + (int) (10.0 * (rand() / (RAND_MAX +
and never by anything resembling
j = 1 + (rand() % 10);
(which uses lower-order bits)."
What they wrote was applicable in
the 80s, back when the pseudo-random number generators they used were so
bad that the lowestmost bit was alternating 0 1 0 1 0 1 and the
next-to-lowermost bit was part of a cycle like 0 0 1 1 0 0 1 1, etc.
Needless to say, such a pseudo-random number generator doesn't pass some
rather fundamental statistical test (cf. Seminumerical Algorithms by
Knuth), and I'd tend to put the blame on the generator, not on the
program that uses it.
The Linux rand() function does not have this problem, so can't this section be cut out of the man page, or failing that how about adding a note:
"Most modern rand() functions, including the one provided on Linux systems,
do not suffer from this problem, so using expressions like rand() % 10 works fine."
Version-Release number of selected component (if applicable):
Steps to Reproduce:
The rand manual page is part of the man-pages package. I'm reassigning this bug
to that package. Regardless, I suspect the content is actually from upstream,
so fixing it may not be directly in the hands of anyone from Fedora.
Thanks. Fixed in man-pages-2.43-7.fc7.