View Single Post
Old 05-23-2004, 05:02 PM   #8 (permalink)
joe_bruin
LOAD "*",8,1
 
Join Date: Feb 2003
Location: la.ca.us
Posts: 254
joe_bruin is on a distinguished road
that is ancient history, and does not hold true for any modern system. man rand sayeth:

Code:
NOTES
       The  versions of rand() and srand() in the Linux C Library
       use the same random number generator as random() and sran_
       dom(),  so the lower-order bits should be as random as the
       higher-order bits.  However, on older  rand()  implementa_
       tions,  the lower-order bits are much less random than the
       higher-order bits.

       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+1.0));

              and never by anything resembling

                     j=1+(rand() % 10);

              (which uses lower-order bits)."
besides, if you were worried about real random values, you would use the entropy gathering random device or a real random number generator (like those found on most processors) instead of rand(), and you would not have an implemetation that seems to favor numbers (one out of 3 values for your seed will be a number, even though numbers make up only 16% of the textspace).
joe_bruin is offline   Reply With Quote