!---------------------------------------------------------------------!
!                                                                     !
!    Initialize the HPF random number generator                       !
!                                                                     !
!    Ideally we would like a good parallel random number generator,   !
!    but we are using the Fortran 90 RANDOM_NUMBER intrinsic.         !
!    Need to find out the number of seeds used by this generator,     !
!    and initialize them. Here we use a simple linear congruential    !
!    generator just to set up the seed array.                         !
!                                                                     !
!---------------------------------------------------------------------!
      
      SUBROUTINE HPF_RANDOM_SEED(seed)
      IMPLICIT NONE
      INTEGER seed
      INTEGER i, n
      INTEGER, DIMENSION(:), ALLOCATABLE :: seed_array

! Find out the size of the seed array used in the Fortran 90 intrinsic 
! random number generator
      CALL random_seed(size=n)
! Set up the initial seeds using a simple linear congruential generator
      ALLOCATE( seed_array(n) )
      FORALL(i=1:n) seed_array(i) = MOD(i*4096+150889+seed,714025 )
! Initialize the intrinsic random number generator
      CALL random_seed( put=seed_array(1:n) )
      DEALLOCATE( seed_array )

!C     PRINT *, 'Size of RNG seed array = ', n

      RETURN
      END SUBROUTINE
 
      
!----------------------------------------------------------------------!
!                                                                      !
!     Call the HPF parallel random number generator.                   !
!                                                                      !
!----------------------------------------------------------------------!

      SUBROUTINE HPF_RANDOM_NUMBER(randnum)
      USE global_variables
      REAL randnum(0:dimm1,0:dimm1)

      CALL RANDOM_NUMBER(randnum)

      RETURN
      END SUBROUTINE

      
!----------------------------------------------------------------------!
!                                                                      !
!     Print out the random numbers.                                    !
!                                                                      !
!----------------------------------------------------------------------!

      SUBROUTINE print_rand
      USE global_variables
      INTEGER i,j

      DO i=0,dimm1
        DO j=0,dimm1
          WRITE(10,'(F9.6)') ranum(i,j)
        ENDDO
      ENDDO

      RETURN
      END SUBROUTINE

