% Simulate penny matching.

n=1000
p=.5 % probability of heads
   
flip=rand(1,n)<p; % 0=tails; 1=heads
x=2*flip-1; % plus or minus ones
fortune=[0 cumsum(x)];

plot(0:n,fortune)