From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,4033beee35bb066,start X-Google-Attributes: gid103376,public X-Google-Thread: 104ef1,f546474144fabe5b X-Google-Attributes: gid104ef1,public From: jmatthews@nova.wright.edu (Dr. John B. Matthews) Subject: Re: random number generation -> PLEASE HELP! Date: 1996/09/05 Message-ID: <1996Sep5.165031@nova.wright.edu>#1/1 X-Deja-AN: 178733796 references: organization: Wright State University newsgroups: comp.lang.pascal.mac,comp.lang.ada Date: 1996-09-05T00:00:00+00:00 List-Id: In article , Oleg Krivosheev writes: > ica2ph@alpha1.csv.ica.uni-stuttgart.de (Peter Hermann) writes: >> Justin Vandenbroucke (rva036@lulu.acns.nwu.edu) wrote: >> : Does anyone know how to generate "random" numbers in pascal? I know BASIC >> : has a standard function that does it, and I know there is some actual code >> >> Ada95, the natural successor of Pascal, has a standard function, of course. >> see http://lglwww.epfl.ch/Ada/ > > C, the natural successor of assembler, has it too... And who cares? > THere are no words in standard about required rnd genertor quality, so > it's hardly usefull for anything but (simple) games Nonsense. GNAT (the GNU Ada compiler from NYU; http://www.gnat.com/) and MacOS (http://www.apple.com) have very satisfactory psuedo- random number generators. The former is available in source from ftp://ftp.cs.nyu.edu/pub/gnat; the latter is shown below. unit ACMRandom; interface procedure SetACMSeed (seed: LongInt); function ACMRandom: LongInt; implementation var acmRandSeed: LongInt; {static variable} procedure SetACMSeed (seed: LongInt); begin if seed = 0 then seed := 1; if seed < 0 then seed := -seed; acmRandSeed := seed; end; function ACMRandom: LongInt; {"minimal standard random number generator" proposed by} {Parker & Miller in CACM, 1988; it has period (2^31)-1} var lo, hi, test: LongInt; begin hi := acmRandSeed div 127773; lo := acmRandSeed mod 127773; test := 16807 * lo - 2836 * hi; if test > 0 then acmRandSeed := test else acmRandSeed := test + maxLongInt; ACMRandom := acmRandSeed; end; end. program RandomTest; uses QuickDraw, ACMRandom; var i: Integer; begin randSeed := 123456789; SetACMSeed(randSeed); for i := 1 to 25 do WriteLn(Random : 7, randSeed : 12, ACMRandom : 12); end. John ---------------------------------------------------------------- Dr. John B. Matthews jmatthews@nova.wright.edu; john_matthews@ccmail.dayton.saic.com "Whom the gods would destroy, they first invite to program in C"