[A83] Re: [OT] Random


[Prev][Next][Index][Thread]

[A83] Re: [OT] Random




Olle Hedman writes:
> Make sure you really use the one you have in a good way, before going
> looking for a "better random algoritm".
> Most people mess up the seeding of the random routine, makeing the
> result bad, no matter how good the routine is.

Another point that is possibly more important is how you get the result.
Some generators tend to have more randomness in the high order bits.  The
following is taken from rand(3) from the GNU glibc man pages:

       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
follow-
       ing 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)."

--
David Phillips <david@acz.org>
http://david.acz.org/




Follow-Ups: References: