% random_walk2.m
%
%  Estimate the chances of falling off a plank.
%
n = input ( 'Enter N, the number of tests: ' );
m = 0;

for i = 1 : n

  position = 0;

  for step = 1 : 20

    step_size = randi ( [ -1, +1 ] );
    position = position + step_size;

    if ( position < -5 || +5 < position )
      m = m + 1;
      break;
    end 

  end

end

fprintf ( '  Estimated falling probabiity is %g\n', m / n );

