Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uwm.edu!bionet!hayes.fai.alaska.edu!acad3.fai.alaska.edu!ftpam1 From: ftpam1@acad3.fai.alaska.edu (MUNTS PHILLIP A) Newsgroups: comp.lang.pascal Subject: Re: help on random number generator & tpu display requested Message-ID: <1990Jul21.211554.13179@hayes.fai.alaska.edu> Date: 21 Jul 90 21:15:54 GMT References: <23899@adm.BRL.MIL> <1990Jul19.180723.8770@hayes.fai.alaska.edu> <1990Jul21.115203.2435@maytag.waterloo.edu> Sender: usenet@hayes.fai.alaska.edu (J Random USENET) Reply-To: ftpam1@acad3.fai.alaska.edu Organization: University of Alaska Fairbanks Lines: 66 News-Software: VAX/VMS VNEWS 1.3-4 In article <1990Jul21.115203.2435@maytag.waterloo.edu>, dmurdoch@watstat.uwaterloo.ca (Duncan Murdoch) writes... >In article <1990Jul19.180723.8770@hayes.fai.alaska.edu> ftpam1@acad3.fai.alaska.edu writes: >>In article <23899@adm.BRL.MIL>, NELIS%NLR.nl@cunyvm.cuny.edu (W.J.M. Nelis, NLR-NOP) writes... >>>-1- Which pseudo random number is used by TP? It is a multiplicative >>> linear congruential generator, but I can't determine its parameters. >> >> See the article in the October 1988 issue of "Communications of the ACM" >>for stuff on random number generators. Don't use the built-in version. > >What problems does the built-in one have? > >Duncan Murdoch Most presently used random number generators have arithmetic overflow in the internal calculations, which causes strange things to the sequences. Hence the large body of lore concerning which seeds to use (or not use!). A generator without overflow (the article referenced above evades it with various clever techniques) will always generate the entire sequence, no matter what seed you use. The article is actually pre-5.5, so it is possible that they have fixed it. Last year in a DSP class we did some simulations. Generators used by other students included those intrinsic to MS Basic and MS Fortran and generated noticeably spiky results. I used the "Minimal Standard Generator" described in the article and my results were absolutely flat. I will append my random number generator unit. Philip Munts N7AHL NRA Extremist, etc. University of Alaska, Fairbanks UNIT MSRandom; INTERFACE FUNCTION random(VAR seed : longint) : real; IMPLEMENTATION (* From CACM Oct 1988 *) FUNCTION random(VAR seed : longint) : real; CONST a = 16807; m = 2147483647; q = 127773; r = 2836; VAR lo, hi, test : longint; 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; END.