urand - c ia=8*idint(halfm*datan(1.d0)/8.D0)+5

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
real function urand(iy) integer iy c urand is a portable uniform random number generator based on c suggestions given by D.E. Knuth and appearing in Computer Methods c c The integer iy should be initialized to an arbitrary integer prior c to the first invocation of urand. The calling program should not c the value of iy between subsequent calls to urand. values of urand c will be returned in the interval (0,1)/ integer ia,ic,itwo,m2,m,mic double precision halfm real s double precision datan,dsqrt data m2/0/,itwo/2/ save ia,ic,itwo,m2,m,mic,s if(m2.ne.0)go to 20 c c if first entry, compute machine integer word length c m=1 10 m2=m m=itwo*m2 if(m.gt.m2)go to 10 halfm=m2 c c compute multiplier and increment for linear congruential method
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: c ia=8*idint(halfm*datan(1.d0)/8.D0)+5 ic=2*idint(halfm*(0.5d0-dsqrt(3.d0)/6.d0))+1 mic=(m2-ic) c c s is the scale factor for converting to floating point c s=0.5/halfm c c compute next random number c 20 iy=iy*ia c c the following statement is for computers which do not allow c integer overflow on addition c if(iy.gt.mic)iy=(iy-m2)-m2 c iy=iy+ic c c the following statement is for computers where the word length c for addition is greater than for multiplication c if(iy/2.gt.m2)iy=(iy-m2)-m2 c c the following statement is for computers where integer overflow c affects the sign bit c if(iy.lt.0)iy=(iy+m2)+m2 c urand=float(iy)*s return end...
View Full Document

Page1 / 2

urand - c ia=8*idint(halfm*datan(1.d0)/8.D0)+5

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online