"Steve Schveighoffer" <schvei...@yahoo.com> wrote in message news:gnal9n$19a...@digitalmars.com...
On Sun, 15 Feb 2009 17:27:38 -0800, Andrei Alexandrescu wrote:

Ok. Let me just note that rand()%max is a lousy method of generating
random numbers between 0 and max-1 and everybody should put that in the
bin with Popular Examples That Should Never Be Used, together with
exponential Fibonacci, linear-space factorial, and bubblesort.

Do you mean rand()%max specifically in the case of the C function rand
()?  Or using %max on any random number generator in general.  If the
first case, I totally agree, and I found out that from experience first,
then googling second :)  But if the latter, I wasn't aware that all RNGs
were bad at randomizing the lower bits, so could you explain why?

It's also possible that Lionello meant the latter case as well.

Actually, I forgot to add that I always use divisors of RAND_MAX ;-)

L.

Reply via email to