Nbody6
ran2.f
Go to the documentation of this file.
1  FUNCTION ran2(idum)
2 *
3 * Random number generator (Press et al. second edition).
4 * ------------------------------------------------------
5  implicit double precision(a-h,o-z)
6  INTEGER idum,im1,im2,imm1,ia1,ia2,iq1,iq2,ir1,ir2,ntab,ndiv
7  INTEGER idum2,j,k,iv,iy
8  common/rand2/ iy,idum2,iv(32),ixyz(65)
9 c REAL ran2,AM,EPS,RNMX
10  parameter(im1=2147483563,im2=2147483399,am=1.d0/im1,imm1=im1-1,
11  *ia1=40014,ia2=40692,iq1=53668,iq2=52774,ir1=12211,ir2=3791,
12  *ntab=32,ndiv=1+imm1/ntab,eps=1.2d-7,rnmx=1.d0-eps)
13 * INTEGER idum2,j,k,iv(NTAB),iy
14 * SAVE iv,iy,idum2
15 * DATA idum2/123456789/, iv/NTAB*0/, iy/0/
16 * DATA IY,IDUM2,IV,IXYZ /0,123456789,32*0,65*0/
17  if (idum.le.0) then
18  idum=max(-idum,1)
19  idum2=idum
20  do 11 j=ntab+8,1,-1
21  k=idum/iq1
22  idum=ia1*(idum-k*iq1)-k*ir1
23  if (idum.lt.0) idum=idum+im1
24  if (j.le.ntab) iv(j)=idum
25 11 continue
26  iy=iv(1)
27  endif
28  k=idum/iq1
29  idum=ia1*(idum-k*iq1)-k*ir1
30  if (idum.lt.0) idum=idum+im1
31  k=idum2/iq2
32  idum2=ia2*(idum2-k*iq2)-k*ir2
33  if (idum2.lt.0) idum2=idum2+im2
34  j=1+iy/ndiv
35  iy=iv(j)-idum2
36  iv(j)=idum
37  if(iy.lt.1)iy=iy+imm1
38  ran2=min(am*iy,rnmx)
39  return
40  END
41 C (C) Copr. 1986-92 Numerical Recipes Software ]vrt43D04.