drbitboy
Lifetime Supporting Member
OT (snort)
OT OT OT
Two out of 10k looks about right, but I'll have to think about why my two-the-same validation is off by a percent or so.
OT OT OT
Two out of 10k looks about right, but I'll have to think about why my two-the-same validation is off by a percent or so.
$ more 4.py
from random import randint as ri
counts = [0]*100
last10 = [ri(0,99) for i in range(10)]
for i in last10: counts = 1
inext,total2,total4,totaltest,samples = 0,0.0,0.0,0.0,list()
twos,fours = set(),set()
try:
while True:
irand = ri(0,99)
ilast = last10[inext]
if 2 == counts[ilast]: twos.remove(ilast)
counts[ilast] -= 1
if 3 == counts[ilast]: fours.remove(ilast)
counts[irand] += 1
if 2 == counts[irand]: twos.add(irand)
elif 4 == counts[irand]: fours.add(irand)
totaltest += 1
if len(twos):
total2 += 1
if len(fours):
total4 += 1
tup = (total2,total4 ,totaltest
,total2/totaltest,total4/totaltest,)
if len(fours) and (0.0 == (total4 % 50)):
print(tup)
samples.append(tup)
last10[inext] = irand
inext += (inext < 9) and 1 or -8
except KeyboardInterrupt: pass
p2 = 100.**(-9)
for i in range(91,100): p2 *= float(i)
import matplotlib.pyplot as plt
total2s,total4s,totaltests,total2prob,total4prob = zip(*samples)
fix,(ax2,ax4,) = plt.subplots(1,2, sharex=True)
ax2.plot(totaltests,total2prob)
ax2.axhline(1.-p2)
ax4.plot(totaltests,total4prob)
plt.show()