Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!ames!uakari.primate.wisc.edu!unmvax!pprg.unm.edu!topgun.dspo.gov!lanl!ttw From: ttw@lanl.gov (Tony Warnock) Newsgroups: comp.sys.ibm.pc Subject: Re: Stuck on pc random number generation : help Summary: portable random number generator source Keywords: beta testing Message-ID: <14039@lanl.gov> Date: 6 Sep 89 21:52:49 GMT References: <7561@microsoft.UUCP> <1991@leah.Albany.Edu> <6474@columbia.edu> Distribution: usa Organization: Los Alamos National Laboratory Lines: 33 Here is a portable random number generator. It gives the same sequence of numbers on PC's, VAX's, CRAY's, etc. FUNCTION fran () c c...portable random number generator c c A..........temporary partial product c B..........temporary partial product c GL.........left hand part of multiplier c GR.........right hand part of multiplier c P..........2**24 c Q..........2**(-24) c SEED.......random number internal value c SMALL......2**(-49) c DOUBLE PRECISION p, q, a, b, seed, gl, gr, small PARAMETER (p=2.**24, q=2.**(-24), gl=1136868.d0, gr=6328637.d0) PARAMETER (small=2.**(-49)) REAL fran SAVE /rhyzome/ COMMON /rhyzome/ seed(2) c a=gr*seed(2)+1.0d0 b=gl*seed(2)+gr*seed(1)+dint(a*q) seed(1)=b-DINT(b*q)*p seed(2)=a-DINT(a*q)*p fran=((seed(1)*p+seed(2))*q*q)+small RETURN END