%------------------------------------------------------------
% THK:
%   I try to be as lean and mean as possible here, since we're 
%   comparing the running time to Power Iteration
% Args:
%   xi: Initial node
%   xj: final node
%------------------------------------------------------------

function xj = random_surfer(xi)

global eps P;

while(rand>eps) % Keep on surfing
    p  = cumsum(P(xi,:));
    xi = find(rand<p,1);
end

xj = xi;