!********o*********o*********o*********o*********o*********o*********o**
! This program demonstrates how to use fortran's pseudo-random number
! generator (PRNG).
!
! The PRNG is not truly random.  Given the same initial state, it will
! produce the same sequence of numbers every time.  The idea is that
! because the sequence seems unpredictable, it is random.
!
! Inputs
!   A decision from the user about whether to continue or not.
!
! Outputs
!   A series of random numbers.
!---------------------
! Author:   Bob Harris
! Class:    CMPSC 201F
! Section:  1234
! Date Due: 12 Nov 2003
!********o*********o*********o*********o*********o*********o*********o**

program simplyrandom

implicit none

real      :: r
character :: answer

! 'seed' the pseudo-random number generator;  see Nyhoff & Leestma
! page A47;  this is supposed to set the PRNG to a different initial
! state every time we run the program, but it doesn't;  for real
! simulations, we will need to change this so that we can either set
! a specific seed, or use the current time of day as the seed

call RANDOM_SEED

do

    ! get the next number in the pseudo-random sequence;  see Nyhoff &
    ! Leestma page A47;  the subroutine RANDOM_NUMBER will place the
    ! number in r;  That number will be in the range 0 <= r < 1

    call RANDOM_NUMBER(r)
    print *, "random number is: ", r

    ! ask the user if we should keep going

    print *, "thank you sir, may I have another?"
    read  *, answer
    if ((answer == 'N') .or. (answer == 'n')) exit

    end do

end program simplyrandom

