      PROGRAM DICE
************************************************************************
* This program uses a random number generator to simulate rolling a    *
* pair of dice several times, counting the number of times a specified *
* number of spots occurs.  Identifiers used are:                       *
*    SPOTS  : number of spots to be counted                            *
*    COUNT  : number of times SPOTS occurred                           *
*    NROLLS : number of rolls of dice                                  *
*    R1, R2 : two random real numbers in the range 0 to 1              *
*    DIE1,                                                             *
*    DIE2   : number of spots on die #1, #2, respectively              *
*    PAIR   : sum of DIE1 and DIE2 = total # of spots on the dice      *
*    ROLL   : counts dice rolls                                        *
*    RESPON : user response                                            *
*    RANDOM : random number generator (subroutine)                     *
*                                                                      *
* Input:  NROLLS, SPOTS, RESPON, seed for random number generator      *
* Output: User prompts, and the relative frequency of the number of    *
*         spots                                                        *
************************************************************************

      INTEGER SPOTS, COUNT, NROLLS, DIE1, DIE2, PAIR, ROLL
      REAL R1, R2
      CHARACTER*1 RESPON

      PRINT *, 'ENTER NUMBER OF TIMES TO ROLL THE DICE:'
      READ *, NROLLS
      PRINT *, 'ENTER A SEED FOR THE RANDOM NUMBER GENERATOR:'
      READ *, R1

* Begin the simulation

 10   CONTINUE
         PRINT *, 'ENTER NUMBER OF SPOTS TO COUNT:'
         READ *, SPOTS
         COUNT = 0
         DO 20 ROLL = 1, NROLLS
            CALL RANDOM(R1)
            CALL RANDOM(R2)
            DIE1 = 1 + INT(6*R1)
            DIE2 = 1 + INT(6*R2)
            PAIR = DIE1 + DIE2
            IF (PAIR .EQ. SPOTS) COUNT = COUNT + 1
 20      CONTINUE

         PRINT 30, SPOTS,  REAL(COUNT) / REAL(NROLLS)
 30      FORMAT (1X, 'RELATIVE FREQUENCY OF', I2, ' WAS', F6.3 /)

         PRINT *, 'MORE ROLLS (Y OR N)?'
         READ '(A)', RESPON
      IF (RESPON .EQ. 'Y') GO TO 10

      END

**RANDOM****************************************************************
* This subroutine generates a random real number in the interval from  *
* 0 to 1.  The variable M is initially the seed supplied by the        *
* user;  thereafter, it is the random integer generated on the pre-    *
* ceding call to the function and saved using the SAVE statement.      *
* NOTE:  The constants 2147483647 and .4656613E-9 used in this sub-    *
* program are appropriate when it is executed on a machine having      *
* 32-bit memory words.  For a machine having M-bit words, these two    *
* constants should be replaced by the values of  2**M - 1  and         *
* 1/(2**M - 1), respectively.                                          *
************************************************************************

      SUBROUTINE RANDOM(RANNUM)

      INTEGER M, CONST1
      REAL RANNUM, CONST2
      PARAMETER (CONST1 = 2147483647, CONST2 = .4656613E-9)
      SAVE
      DATA M /0/

      IF (M .EQ. 0) M = INT(RANNUM)
      M = M * 65539
      IF (M .LT. 0) M = (M + 1) + CONST1
      RANNUM = M * CONST2

      END
