c
      PROGRAM ran
      IMPLICIT REAL*8(A-H,O-Z)

      do i=1,10
      x=ran1(i)
      write(*,*)x
      end do

      stop
      end
c
c *** RAMdAM Function **
c
      function ran1(idum)
      IMPLICIT REAL*8(A-H,O-Z)
      parAMeter(IA=16807,IM=2147483647,AM=1./IM,IQ=127773,IR=2836
     *         ,NTAB=32,NDIV=1+(IM-1)/NTAB,eps=1.2d-7,RNMX=1.-eps)
      dIMension iv(NTAB)
      save iv,iy
      data iv/NTAB*0/, iy/0/
c
      if(idum.le.0.or.iy.eq.0)then
        idum=max(-idum,1)

      write(*,*)'idum',idum

        do j=NTAB+8,1,-1
          k=idum/IQ
          idum=IA*(idum-k*IQ)-IR*k
          if(idum.lt.0)idum=idum+IM
          if(j.le.NTAB)iv(j)=idum
        end do
	iy=iv(1)
      end if
c
      k=idum/IQ
      idum=IA*(idum-k*IQ)-IR*k
      if(idum.lt.0)idum=idum+IM
      j=1+iy/NDIV
      iv(j)=idum
      ran1=min(AM*iy,RNMX)
c
      return
      end
