update new files
[unres.git] / source / maxlik / src_MD_T_maxlik-NEWCORR-PMF / ran1.f
1       REAL FUNCTION ran1(idum)
2       INTEGER idum,IA,IM,IQ,IR,NTAB,NDIV
3       REAL AM,EPS,RNMX
4       PARAMETER (IA=16807,IM=2147483647,AM=1./IM,IQ=127773,IR=2836,
5      *     NTAB=32,NDIV=1+(IM-1)/NTAB,EPS=1.2e-7,RNMX=1.-EPS)
6 C     "Minimal" random number generator of Park and Miller with Bays-Durham shuffle and
7 C     added safeguards. Returns a uniform random deviate between 0.0 and 1.0 (exclusive of
8 C     the endpoint values). Call with idum a negative integer to initialize; thereafter, do not
9 C     alter idum between successive deviates in a sequence. RNMX should approximate the largest
10 C     floating value that is less than 1. Recommended for seqences smaller than 100e6 (i.e. 5%
11 C     of ran1's period.
12 C     (from Press etal, Numerical Recipes in Fortran 77)
13 CcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccC
14       INTEGER j,k,iv(NTAB),iy
15       SAVE iv,iy
16       DATA iv /NTAB*0/, iy /0/
17       if (idum.le.0.or.iy.eq.0) then  ! initialize
18          idum=max(-idum,1)            ! load the shuffle table (after 8 warmups)
19          do j=NTAB+8,1,-1
20             k=idum/IQ
21             idum=IA*(idum-k*IQ)-IR*k
22             if (idum.lt.0) idum=idum+IM
23             if (j.le.NTAB) iv(j)=idum
24          enddo
25          iy=iv(1)
26       endif
27       k=idum/IQ                       ! start here when not initializing
28       idum=IA*(idum-k*IQ)-IR*k
29       if (idum.lt.0) idum=idum+IM
30       j=1+iy/NDIV
31       iy=iv(j)
32       iv(j)=idum
33       ran1=min(AM*iy,RNMX)
34       return
35       END