Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!purdue!ames!oliveb!apple!desnoyer From: desnoyer@Apple.COM (Peter Desnoyers) Newsgroups: comp.lang.c Subject: Re: Randomness of MSC 5.1 rand() Message-ID: <30294@apple.Apple.COM> Date: 8 May 89 17:31:50 GMT References: <1598@oregon.uoregon.edu> Organization: Apple Computer Inc, Cupertino, CA Lines: 19 In article <1598@oregon.uoregon.edu> michelbi@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