! this is a piece of f90 code to choose the direction of a step in a Random Walk! on a square lattice 
!
! it uses the intrinsic f90 features:
!     random_number
!     floor(a)      greatest integer  <= a
!     select case   analogous to if, selects alternative blocks of instructions 
!
! In a RW steps left,right up or down are chosen at random by taking a random 
! number rand in the interval 0-1 with the built-in subroutine random_number
! 
! Since 0<= rand <1  ==>  floor(rand*4) = 0 or = 1 or = 2 or = 3
! Steps to the right for 0<= rand < 0.25, i. e. for floor(rand*4)=0  etc.
! 
! The vector N(0:3) contains how many step have been taken : 
! right (N(0)), left (N(1)), up (N(2)), down (N(3)) 
! X and Y cartesian coordinates of walker during a walk of nstep steps

	do j=1,nstep
		call random_number(rand)
		select case(floor(rand*4))
			case(0)
				N(0)=N(0)+1
				X=X+1
			case(1)
				N(1)=N(1)+1
				X=X-1
			case(2)
				N(2)=N(2)+1
				Y=Y+1
			case(3)
				N(3)=N(3)+1
				Y=Y-1
		end select
	end do
