%RUNS

%%% parameters

p=0.5;
n=1000000;

s=zeros(1,n);
sr=zeros(1,n);

clf reset;
%grid on;
%ylim([0.3,0.7]);
%hold on;
%h = axes('Position',[0 0 1 1],'Visible','off');

x=rand(1,n);
s=(x<=p);
%s3=randi([0,1],1,n);

cr=0;
for (i=1:n)
    if (s(i)==0) cr=0; else cr=cr+1; 
    end
    sr(i)=cr;
end

t=[1:n];
 
plot(t, cummax(sr), 'Color', [0,0,1], 'LineWidth',2);

% plot(t, 0.5+zeros(1,n), 'Color', [0,0,0]);
% plot(t, p1+zeros(1,n), 'Color', [0.5,0.5,0.5]);
% plot(t, p2+zeros(1,n), 'Color', [0.5,0.5,0.5]);
 
str=strcat('prob. p', sprintf('=%1.4f', p));
legend(str,'FontSize',10, 'Location','southeast');

xlabel('no. of coin tosses','FontSize',10);
ylabel('longest run of 1s','FontSize',10);

title('Run size','FontSize',10);
hold off;