Question: The C version is below: #include float expdev(long *idum) /*Returns an exponentially distributed, positive, random deviate of unit mean, using ran1(idum) as the source of


\#include math. h> float ranl(long *idum) /*"Minimal" random number generator of Park and Miller with Bays-Durham shuffle and added safeguards. Returns a uniform random deviate between 0.0 and 1.0 (exclusive of the endpoint values). Call with idum a negative integer to initialize; thereafter, do not alter idum between successive deviates in a sequence. RNMX should approximate the largest floating value that is less than 1.\% \{ \#define IA 16807 \#define IM 2147483647 \#define AM (1.0/IM) \#define IQ 127773 \#define IR 2836 \#define NTAB 32 \#define NDIV (1+( IM-1)/NTAB) \#define EPS 1.2e-7 \#define RNMX (1.0-EPS) int j; long k; static long iy =0; static long iv[NTAB]; float temp; //printf("in idum=\%ld",*idum); if (*idum =0;j) \{ k=( *idum)/IQ; //Load the shuffle table (after 8 warm-ups). *idum =IA(idumkIQ)-IR k; if ( idum RNMX) return RNMX; //Because users don't expect endpoint values. else return temp; \} FUNCTION ranl(idum) INTEGER :: idum,IA,IM,IQ,IR,NTAB,NDIV REAL :: ranl,AM,EPS,RNMX PARAMETER (IA=16807,IM=2147483647,AM=1./IM,IQ=127773,IR=2836,& NTAB=32,NDIV=1+(IM1)/NTAB,EPS=1.2e7,RNMX=1,EPS) !"Minimal" random number generator of Park and Miller with Bays-Durham shuffle and !added safeguards. Returns a uniform random deviate between 0.0 and 1.0 (exclusive of !the endpoint values). Call with idum a negative integer to initialize; thereafter, do not !alter idum between successive deviates in a sequence. RNMX should approximate the largest !floating value that is less than 1 . INTEGER : j,k,iv(NTAB),iy SAVE iv,iy DATA iv / NTAB0/, iy /0/ if (idum.le.0.or.iy.eq. 0 ) then idum =max(1 *idum, 1) do j=NTAB+8,1,1 k=idum/LQ idum =IA (idum- kIQ ) IRk if (idum.It.0) idum=idum + IM if (j.le.NTAB) iv(j)=idum end do iy=iv(1) end if k=idum/1Q idum =IA (idum- kIQ )-IR*k if (idum.lt. 0 ) idum=idum +IM j=1+iy/NDIV iy=iv(j) iv(j)=idum ran1=min(AMi,RNMX) return END FUNCTION ranl
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
