C***   RAN
C  UTILITY ROUTINES (SHIFT, RAN, DATIME, CIAO, BUG, LOG)


       INTEGER FUNCTION RAN(RANGE)

C  SINCE THE RAN FUNCTION IN LIB40 SEEMS TO BE A REAL LOSE, WE'LL USE ONE OF
C  OUR OWN.  IT'S BEEN RUN THROUGH MANY OF THE TESTS IN KNUTH VOL. 2 AND
C  SEEMS TO BE QUITE RELIABLE.  RAN RETURNS A VALUE UNIFORMLY SELECTED
C  BETWEEN 0 AND RANGE-1.  NOTE RESEMBLANCE TO ALG USED IN WIZARD.

       IMPLICIT INTEGER(A-Z)
      INTEGER*4 R
       DATA R/0/

       D=1
       IF(R.NE.0)GOTO 1
       CALL DATIME(D,T)
       R=18*T+5
       D=1000+MOD(D,1000)
1       DO 2 T=1,D
2       R=MOD(R*1021,1048576)
       RAN=(RANGE*R)/1048576
       RETURN
       END
