function randomWalk(n,x0,y0)
% Take n steps of random walk starting from (x0,y0).  Display the path.
% In each step, the possible moves are left, right, up, or down.

% possible movements:  ( deltaX(i), deltaY(i) )
  deltaX= [ 1 -1  0  0];
  deltaY= [ 0  0  1 -1]; 
  
x= [x0 zeros(1,n)];  % trajectory in x direction
y= [y0 zeros(1,n)];  % trajectory in y direction

% Perform walk, each step is based on a random integer
for k= 2:n+1
    r= ceil(4*rand(1));  % get a random integer in range 1..4
    x(k)= x(k-1) + deltaX(r);
    y(k)= y(k-1) + deltaY(r);
end 

% Show the walk
plot(x,y,x(1),y(1),'r*',x(end),y(end),'ro')
axis('equal')
title([num2str(n) ' steps of random walk from * to o'])
    