default random object?

Steve Schveighoffer schveiguy at yahoo.com
Sun Feb 15 19:07:35 PST 2009


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.

-Steve



More information about the Digitalmars-d mailing list