Skip to content

Instantly share code, notes, and snippets.

@drathier
Created February 22, 2017 12:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drathier/21909bdaa588ffd712689d128163fd80 to your computer and use it in GitHub Desktop.
Save drathier/21909bdaa588ffd712689d128163fd80 to your computer and use it in GitHub Desktop.
Elm-test #128 regression bug detection rate simulation
import random
for twenty in [3, 4, 5, 6, 7, 8, 9, 10, 12, 15, 17, 20, 22, 25, 27, 30, 33, 37, 40, 44, 50, 54, 60, 64, 70, 74, 80, 84, 90, 94, 100]:
print("#" * 10)
print("twenty", twenty)
n = 10 ** 6
found = 0
for k in range(n):
for x in range(100):
choice = random.randint(0, 9)
if choice == 0:
a = 0
elif choice == 1:
a = twenty
else:
a = random.randint(0, twenty)
if a == 2:
found += 1
break
print("found", found, "/", n, found / n, 1 - found / n) # 0.00760448999
###############
n = 10 ** 6
found = 0
for k in range(n):
seen = set()
for x in range(100):
choice = random.randint(0, 9)
if choice == 0:
a = 0
elif choice == 1:
a = twenty
else:
a = random.randint(0, twenty)
if a in seen:
break
seen.add(a)
if a == 2:
found += 1
break
print("found", found, "/", n, found / n, 1 - found / n, seen)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment