File: SRAND.FT of Disk: Disks/Working/Build-11-03-07
(Source file text) 


C      SUBROUTINE SRAND(ISEED)
C
C  This subroutine sets the integer seed to be used with the
C  companion RAND function to the value of ISEED.  A flag is 
C  set to indicate that the sequence of pseudo-random numbers 
C  for the specified seed should start from the beginning.
C
C     COMMON /SEED/JSEED,IFRST
C
C     JSEED = ISEED
C     IFRST = 0
C
C     RETURN
C     END
      FUNCTION RAND(INIT)
C
C  This function returns a pseudo-random number for each invocation.
C  It is a FORTRAN 77 adaptation of the "Integer Version 2" minimal 
C  standard number generator whose Pascal code appears in the article:
C
C     Park, Steven K. and Miller, Keith W., "Random Number Generators: 
C     Good Ones are Hard to Find", Communications of the ACM, 
C     October, 1988.
C
      DATA MPLIER,MODLUS,MOBYMP,MOMDMP/16807,2147483647,127773,2836/
C
      COMMON  /SEED/JSEED,IFRST
      INTEGER HVLUE, LVLUE, TESTV, NEXTN
C
      IF (IFRST .NE. 0) GOTO 10
        NEXTN = JSEED
        IFRST = 1
10    CONTINUE
C
      HVLUE = NEXTN / MOBYMP
      LVLUE = MOD(NEXTN, MOBYMP)
      TESTV = MPLIER*LVLUE - MOMDMP*HVLUE
      IF (TESTV .LE. 0) GOTO 20
      NEXTN = TESTV
      GOTO 30
20    NEXTN = TESTV + MODLUS
30    CONTINUE
      RAND = REAL(NEXTN)/REAL(MODLUS)
C
      RETURN
      END
      BLOCKDATA RANDBD
      COMMON /SEED/JSEED,IFRST
C
      DATA JSEED,IFRST/123456789,0/
C
      END