c===========================================================
c     ticorr: Tests for initial correlation in random 
c     number sequences for consecutive seeds.
c===========================================================
      program         ticorr

      implicit        none

      real*8          rand                
      integer         iargc,        i4arg

      integer         maxn
      parameter     ( maxn = 1 000 000 )
      real*8          dev(maxn),    vrand(maxn)
c-----------------------------------------------------------
c     Command-line arguments:
c-----------------------------------------------------------
      integer         minseed,      maxseed,
     &                n,            ndiscard,
     &                seed_offset

      integer         i,            seed
      real*8          nint,         vrandi

      logical         ltrace
      parameter     ( ltrace = .false. )

      if( iargc() .lt. 1 ) go to 900

      minseed     = i4arg(1,-1)
      if( minseed .lt. 0 ) go to 900
      maxseed     = i4arg(2,-1)
      if( maxseed .lt. 0 ) go to 900
      n           = min(maxn,i4arg(3,1000))
      ndiscard    = i4arg(4,0)
      seed_offset = i4arg(5,1)

      call dvls(dev,0.0d0,n)
      do seed = minseed , maxseed
         if( ltrace ) then 
            write(0,*) 'Calling srand with seed ', seed
         end if
         call srand(seed)
         do i = 1 , ndiscard
            vrand(i) = rand()
         end do
         do i = 1 , n
            vrand(i) = rand()
         end do
         if( ltrace ) then
            write(0,*) 'Calling srand with seed ', 
     &                  seed + seed_offset
         end if
         call srand(seed+seed_offset)
         do i = 1 , ndiscard
            vrand(i) = rand()
         end do
         do i = 1 , n
            dev(i)   = dev(i) + abs(vrand(i) - rand())
         end do
      end do
      call dvsm(dev,1.0d0/(maxseed - minseed + 1),dev,n)
      call dvwri1(dev,n,6)

      stop

 900  continue
         write(0,*) 'usage: ticorr <minseed> <maxseed> '//
     &              '[<n> <ndiscard> <seed offset>]'
      stop

      end
