Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!munnari.oz.au!uhccux!waikato!ldo From: ldo@waikato.ac.nz (Lawrence D'Oliveiro, Waikato University) Newsgroups: comp.sys.mac.programmer Subject: Re: Is Random() random? Message-ID: <2430.275c1f0b@waikato.ac.nz> Date: 4 Dec 90 09:11:23 GMT References: Organization: University of Waikato, Hamilton, New Zealand Lines: 40 The QuickDraw Random function uses a reasonably good algorithm. It's basically the same as the "minimal standard" one described in the article "Random Number Generators: Good Ones are Hard to Find", by Stephen K Park and Keith W Miller, in Communications of the ACM, volume 31, number 10, October 1988. However, to obey this algorithm *exactly*, you have to ignore the function result from Random, and look at the value of the RandSeed QuickDraw global instead. This takes on uniformly-distributed values from 1 up to 2147483647 (2 ** 31 - 1) inclusive. Here's an example routine which returns a uniformly distributed real number from 0 up to (but not including) 1: Procedure GetRandomReal ( var Result : Real ); Var Ignore : Integer; Begin Ignore := Random; { cause a change to RandSeed } Result := (RandSeed - 1) / 2147483647.0 End {GetRandomReal}; As for the result of the Random function itself, I don't know what its properties (e g autocorrelation and other signs of non-randomness) are. But if you read the article I mentioned above, you'd be less likely to trust any old random number algorithm (or variation thereof) until you've seen the results of some very careful testing. Lawrence D'Oliveiro fone: +64-71-562-889 Computer Services Dept fax: +64-71-384-066 University of Waikato electric mail: ldo@waikato.ac.nz Hamilton, New Zealand 37^ 47' 26" S, 175^ 19' 7" E, GMT+13:00 "...so she tried to break into the father bear's computer, but it was too hard. Then she tried to break into the mother bear's computer, but that was too easy..."