1 real function da_unifva (kdum)
3 !--------------------------------------------------------------------
4 ! Purpose: Minimal random number generator of Park and Miller with
5 ! Bays-Durham shuffle and added safeguards.
6 ! Returns a uniform random deviate between 0.0. and 1.0 (exclusive
7 ! of the endpoint values). Call with kdum a negative integer to
8 ! initialize; thereafter, do not alter kdum between successive
9 ! deviates in sequence. rnmx should approximate the largest
10 ! floating value less than 1.
12 ! See descripiton of function 'ran1', pg. 271.
13 !--------------------------------------------------------------------
17 integer, intent(inout) :: KDUM
19 integer JPIA,JPIM,JPIQ,JPIR,JPNTAB,JPNDIV
20 real PPAM,PPEPS,PPRNMX
22 parameter(JPIA=16807,JPIM=2147483647,JPIQ=127773,JPIR=2836, &
23 JPNTAB=32,JPNDIV=1+(JPIM-1)/JPNTAB, &
24 PPAM=1./JPIM,PPEPS=1.2E-07,PPRNMX=1.-PPEPS)
29 integer NIV(JPNTAB),NIY
31 DATA NIV /JPNTAB*0/, NIY /0/
33 if (trace_use_frequent) call da_trace_entry("da_unifva")
38 if ((KDUM.LE.0).OR.(NIY.EQ.0)) then
43 KDUM = JPIA*(KDUM - IK*JPIQ) - JPIR*IK
45 if (KDUM.lt.0) KDUM = KDUM + JPIM
46 if (JJ.LE.JPNTAB) NIV(JJ) = KDUM
54 KDUM = JPIA*(KDUM - IK*JPIQ) - JPIR*IK
56 if (KDUM.LT.0) KDUM = KDUM + JPIM
61 DA_UNifVA = Min(PPAM*NIY , PPRNMX)
63 if (trace_use_frequent) call da_trace_exit("da_unifva")
65 end function da_unifva