clear all
s=20;
a=13;
b=1;
m=16;
p1=0.5;
n=20;
for J=1:n
   BA=0;
for I=1:m
       n=a*s+b;
u=mod(n,m);
v=u/m;
if v==0
    I=I+1;
else
h1=log(v);
p2=log(1-p1);
h2=h1/p2;
d=fix(h2)-1;
BA=BA+d;
s=u;
end
end
BN(J)=BA;
s=exp(J);
end
 BN=BN';
       save('D:\Practicas_simulacion_MatLab\valoresbinomialnegativa.txt','BN','-ascii');