c-----------------------------------------------------------
c     Demonstrates use of real*8 random number generator
c     'rand' available on SGI machines.  Takes single 
c     integer argument 'nrand', generates 'nrand' random
c     numbers uniformly distributed on [0..1] and writes 
c     them, one per line, to standard output.  Writes 
c     average of all numbers generated (which should approach 
c     0.5 asymptotically) to standard error.
c-----------------------------------------------------------
      program         trand    

      implicit        none

      integer         iargc,       i4arg
      real*8          rand

      real*8          ranval,      sum
      integer         i,           nrand

      if( iargc() .ne. 1 ) go to 900
      nrand = i4arg(1,-1)
      if( nrand .le. 0 ) go to 900

      sum = 0.0d0
      do i = 1 , nrand
c-----------------------------------------------------------
c        Generate a random number
c-----------------------------------------------------------
         ranval = rand()
         sum = sum + ranval
         write(*,*) ranval
      end do

      write(0,*) 
      write(0,*) 'Average: ', sum / nrand

      stop

 900  continue
         write(0,*) 'usage: trand <n>'
      stop
      end
