C--------------------------------------------------------------------------
C
C     This file contains a set of routines that simulate the NAG random
C     number generating routines.
C
C     These routines use the same name as the NAG routines, so it can 
C     simply be compiled and linked with NMRFIT.
C
C     The important points to note are:
C
C     i.   I use the FORTRAN RAN function to generate the random numbers.
C          This may be slightly different on other computers and therefore
C          ought to be checked.
C
C     ii.  The function RAN requires and integer*4 seed number, which I
C          simply call SEED and place in a "transparent" common block.
C
C     iii. The initialisation of SEED to a random starting point (or at 
C          least to a starting point that is different each time) is 
C          performed using the VMS TIME subroutine. This may be different
C          for a different computer.
C
C--------------------------------------------------------------------------


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
