      FUNCTION RANUM()
      Implicit None
c----------------------------------------------------------------------
c  This is the standardized random number generator for NUMONTE, 
c  which currently uses the CERNLIB routine "RANLUX".  It returns 
c  a random number in the interval (0.,1.), the end points excluded.
c
c  RANUM initializes itself depending on flags set by the user.
c  If NEWSEED=.FALSE. then the system default seeds are used
c  If true, seed values saved at the end of the last MC run are used, 
c  as read in by routine SEEDINIT (see "seedinit.F")
c----------------------------------------------------------------------

      REAL RAN,ranum,tinynum

      parameter (tinynum=1.e-19)

      LOGICAL FIRST,AOK
      DATA FIRST /.TRUE./
      if (FIRST) FIRST= .FALSE.

      CALL RANLUX(ran,1)
      RANUM= RAN

      if (RANUM.LT.tinynum) RANUM=tinynum

      AOK = .FALSE.
      IF ((RANUM.LE.1.1).AND.(RANUM.GE.TINYNUM)) AOK = .TRUE.
      IF (.NOT.(AOK)) CALL SEEDINIT(FIRST,314159)

      RETURN
      END


      SUBROUTINE SEEDINIT(FIRST,ISINI)

      IMPLICIT NONE

c----------------------------------------------
c     Initialize (or re-initialize) random 
c     number generator
c----------------------------------------------

      LOGICAL FIRST
      INTEGER ISINI,JSINI,KSINI

      IF (FIRST) THEN
         JSINI = 0
         KSINI = 0
      ELSE
         ISINI = 314159272
         JSINI = 0
         KSINI = 0
      ENDIF         

      CALL RLUXGO(2,ISINI,JSINI,KSINI) !..sets RANLUX seeds

      RETURN
      END
