program rantest
! check use of random numbers in f90
!the seed is given in the program but should be read from input
       implicit none
       real*8:: x,y
       integer, allocatable:: get(:), seed(:), put(:)
       integer::i,size,n

!  This is the processor initialization
   call RANDOM_SEED

! size is the number of elements (values of the seed) which characterize the 
! random number. On the Sun size=4
   call RANDOM_SEED(SIZE=n)
   write(6,*)'#n=',n

!  set up storage for args
   allocate (seed(n))
   allocate (get(n))
   allocate (put(n))

!  Now set some random values in seed. These numbers could be read by a file.

    seed(1) = -1561551495
    seed(2) = -1517742738
    seed(3) = -1873363524
    seed(4) = 192341289


!initialize random sequence with the given values of seed(size)
       call RANDOM_SEED(put=seed(1:n))

!check that indeed the seed has been read correctly, the actual seed will be 
!given in the array get. 
       call RANDOM_SEED(get=seed(1:n))
       write(10,*)'#Seed =',(seed(i), i = 1, n)
       write(6,*) '#Seed =',(seed(i), i = 1, n)
       deallocate(get)


!use the random numbers many times, add test of randomness on results

       do i=1,50000
        call random_number(x)
        call random_number(y)
        write(10,*) i,x,y
       enddo


!ask the value of the seed and begin the new simulation from here
       call RANDOM_SEED(get=seed(1:n))
       write(10,*) '#Seed =',(seed(i), i = 1, n)
       write(6,*)  '#Seed =',(seed(i), i = 1, n)

       end program rantest
