      program rantest
C     ===============

C--------------------------------------------------------------------------
C
C     Test of alternative to NAG random number routines
C
C--------------------------------------------------------------------------

      double precision realr,x
      integer g05dyf
      double precision g05caf

      call g05ccf

      intr = 0
      realr = 0.0d0
      do 1001 i = 1,20000
      intr = intr + g05dyf(1,10)
      realr = realr + g05caf(x)
 1001 continue
      write(6,*) float(intr)/20000.0,realr/20000.0d0

      end

C==========================================================================


      integer function g05dyf(m,n)
C     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~

C--------------------------------------------------------------------------
C
C     gives a random integer between m and n selected from a uniform 
C     distribution
C
C--------------------------------------------------------------------------

      common /seedcom/ seed

      integer seed

      mn = m - n
      a = (ran(seed) * mn) - 0.5

      g05dyf = n + nint(a)

      end


C==========================================================================


      subroutine g05ccf
C     ~~~~~~~~~~~~~~~~~

C--------------------------------------------------------------------------
C
C     Selects a random seed for the random number generators. Here I use
C     the TIME subroutine provided by VMS. This may not be standard, so you 
C     may need to alter it. What I do is to read the time out as an
C     integer*8 number, then select the last part of the number as my
C     "random" seed.
C
C--------------------------------------------------------------------------

      common /seedcom/ seed

      integer seed
      integer*8 iseed
      character*80 buffer

      call time(iseed)
      write(buffer,*) iseed

      read(buffer(17:),*) seed

      return
      end


C==========================================================================


      real*8 function g05caf(x)
C     ~~~~~~~~~~~~~~~~~~~~~~~~~

C--------------------------------------------------------------------------
C
C    gives a random number (real*8) selected from a uniform distribution 
C    between 0.0 and 1.0. x is a dummy real*8 variable.
C
C--------------------------------------------------------------------------

      common /seedcom/ seed

      double precision x
      integer seed

      g05caf = ran(seed)

      end
