% calculate probality of hitting 0 or n
% starting from k

function hit_bdy(n,trials)
   prob=zeros(1,n-1);
  for k=1:n-1
    for j=1:trials
	x=k;
	while (x>0) & (x<n)
          x=x+2*round(rand)-1;
        end % while
	if x == n
           prob(k)=prob(k)+1;
        end 
    end % j
  end % for k
  prob=prob/trials;
  figure
  hold on;
  title('probablity of hitting right end point');
  plot(prob);

  return
