Randomness of MSC 5.1 rand()

Peter Desnoyers desnoyer at Apple.COM
Tue May 9 03:31:50 AEST 1989


In article <1598 at oregon.uoregon.edu> michelbi at oregon.uoregon.edu (Michel Biedermann) writes:
>How good (i.e. random) is the rand() function in MSC 5.1/QC 2.0?

Here's one easy test:
   int i; double sum=0;			
   for (i = 0; i < 20; i++){
     while( (double)rand()/MAX_RAND > 0.0001);	/* wait */
     sum += (double)rand()/MAX_RAND;	/* then do something random */
   }
   printf( "%f\n", sum/20.0);

On the VAX I use (BSD 4.3?) I get 0.44, on Mac MPW I get 0.43. (both
are reasonable.) On at least one version of Turbo Pascal for the PC
you will get 0.25 or less. (my boss had this persistant bug in a small
simulation of random packet arrivals - the average packet size was
max/4 or max/8, rather than max/2. Turns out his code looked like the
code above.)

				Peter Desnoyers



More information about the Comp.lang.c mailing list