random() error in Turbo C++

Niels J|rgen Kruse njk at diku.dk
Mon Sep 10 02:33:04 AEST 1990


daveg at near.cs.caltech.edu (Dave Gillespie) writes:

>>>>>> On 8 Sep 90 20:15:20 GMT, njk at diku.dk (Niels J|rgen Kruse) said:
>> This require 2 divisions however.  Here is an algorithm, that
>> only require one division:

I used rand() because Karl Heuer did and because it is the ANSI
standard interface for getting random numbers.  Nothing other
than inertia prevents rand() from being good.  Good random
number generators don't have to be slower than bad ones.  Just
plug a good random number generator into the code i gave instead
of rand(), if the one you are using is bad.

>Most rand() implementations use linear congruential random number
>generators, which are notorious for having unpleasant properties
>in their low bits.  Experts recommend always dividing instead of
>mod'ing, so that you are using the high bits of the result of
>rand().

Oh.  So experts use rand()?  ;-)
-- 
Niels J|rgen Kruse 	DIKU Graduate 	njk at diku.dk



More information about the Comp.lang.c mailing list