Path: utzoo!attcan!uunet!tut.cis.ohio-state.edu!zaphod.mps.ohio-state.edu!rpi!uupsi!mstr!sc7.hgc.edu!rhb From: rhb@sc7.hgc.edu (Roger H. Brown) Newsgroups: comp.sys.mac.programmer Subject: Re: Random number Generator wanted. Keywords: Random number Message-ID: <409@mstr.hgc.edu> Date: 28 Jun 90 20:21:38 GMT References: <152@asacsg.mh.nl> Sender: news@mstr.hgc.edu Reply-To: rhb@sc7.hgc.edu (Roger H. Brown) Organization: The Hartford Graduate Center, Hartford CT. Lines: 48 In article <152@asacsg.mh.nl> kr@asacsg.mh.nl (Koos Remigius) writes: > >What I need is a random number generator that gives me a random LongInt back. >The random number I want must lis between 0 and 2097151. > >Koos Remigius. If you can get your hands on a copy of the following article you will get the full details of generating uniform random integers between 1 and 2147483646 or up to maxInt = 2^31 -1. See: S.K. Park and K.W. Miller, "Random Number Generators: Good Ones are Hard To Find," Communications of the ACM, Vol.31, No. 10, 1988. Until then, you might want to play with the following code: var seed : integer function Random : real (* Uses integer arith, yet returns a real between 0.0 and 1.0 *) const a = 16807; m = 2147483647; q = 127773; (* m div a *) r = 2836; (* m mod a *) var lo, hi, test : integer; begin hi := seed div q; lo := seed mod q; test := a * lo - r * hi; if test > 0 then seed := test else seed := test + m; Random := seed / m end; Regards |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| | Roger H. Brown GEnie: R.BROWN64 AOL: Roger48 | | Sch. of Eng. & Science rhb@mstr.hgc.edu ...uupsi!mstr!rhb | |_____________________________________________________________________|