      program rwalk01
c-----------------------------------------------------------------
c Random walk in 2 dimensions (2D random walk)
c-----------------------------------------------------------------
c input from a keyboard
c    number of trials
c    number of steps
c output screen
c    initial data and average distance
c Attention!!!
c the code call subroutine 'gettim' to get current time
c that name is not unique, and may be different for different compilers
c You may replace the seed number from current time by some seed number
c-----------------------------------------------------------------
c written by: Alex Godunov
c last revision: October 2006
c-----------------------------------------------------------------
      implicit none
      integer*4 iu, it, is, itests, isteps, iway, x, y
      integer*4 ihour, imin, isec, imsec
      real*4 rand, d, dav

      write (*,*) ' enter numbers of tests and steps'
      read  (*,*) itests, isteps

      call gettim(ihour,imin,isec,imsec)
      iu = imsec*isec*imin+ihour
      call srand(iu)
      dav=0.0

c	open (unit=7,file='randwalk.dat')

      do it=1,itests
        x=0
        y=0
        do is=1,isteps
          iway= int(0.0+4.0*rand())
          if(iway.eq.0) x = x+1
          if(iway.eq.1) x = x-1
          if(iway.eq.2) y = y+1
          if(iway.eq.3) y = y-1
c         write(7,101) x,y
        end do
        d = sqrt((float(x))**2+(float(y))**2)
        dav = dav + d
      end do

      dav = dav/float(itests)
      write(*,100) itests, isteps, dav

100   format(' itests =',i5,'  isteps =',i5,' distance = ',1pe12.3)
101   format(2i6)

      stop
      end