Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site dciem.UUCP Path: utzoo!dciem!dms From: dms@dciem.UUCP (Dave Sweeney) Newsgroups: net.micro.cpm Subject: Re: Random Numbers Message-ID: <1523@dciem.UUCP> Date: Wed, 10-Apr-85 11:42:38 EST Article-I.D.: dciem.1523 Posted: Wed Apr 10 11:42:38 1985 Date-Received: Wed, 10-Apr-85 13:56:11 EST References: <9787@brl-tgr.ARPA> Organization: D.C.I.E.M., Toronto, Canada Lines: 28 Nick Cuccia writes: > > > function Random(var x: integer): real; > > const > A = 2047; (* = 2^11 - 1, a prime number *) > M = 524287; (* = 2^19 - 1, a prime number *) > > begin (* random *) > x := (A*x) mod M; (* finding new seed value *) > Random := x / M; (* finding next number in series *) > end; (* function random *) While A (= 2047) and M (= 524287) are mutually prime (HCF = 1), which is all that is required for the algorithm, A is not a prime number: 2047 = 23 * 89 which will hopefully discourage 16-bit-machine users from using it for M (which must be prime for the series to have full period). Here at DCIEM we use an implementation of the generator described on p. 464 of Knuth's vol. 2, with k = 55, j = 31. As no multiplications or divisions are involved, it is reasonably fast. -- Dave Sweeney, DCIEM {allegra,ubc-vision,linus,ihnp4,uw-beaver,floyd}!utcsrgv!dciem!dms or {allegra,ihnp4,linus,decvax}!utzoo!dciem!dms