News for hackers. Stuff that matters.
Re:Why bad scientific code beats code following "best practi... by Someone on Monday May 12, 2014 @12:40PM (#7733787)
It is often wrong even if random() were to produce perfectly random numbers; random()%NUM, for most values of NUM, will be biased.

For example, if RAND_MAX is 255, random()%10 equals 0, 1, 2, 3, 4, or 5 26/256 of the time, but 6, 7, 8, or 9 only 25/256 of the time.

That's why good libraries have a 'next(maxValue)' function that is more complex than random()%NUM. For example, see lines 251-268 of http://developer.classpath.org/doc/java/util/Random-source.h....

There are no comments on this comment yet.