Skip to content

Instantly share code, notes, and snippets.

@TiddoLangerak
Last active July 5, 2024 14:01
Show Gist options
  • Save TiddoLangerak/252ee6503351d3c50bc5054fa2416776 to your computer and use it in GitHub Desktop.
Save TiddoLangerak/252ee6503351d3c50bc5054fa2416776 to your computer and use it in GitHub Desktop.
Simulate flakiness probability
const nrOfOptions = 10
const samples = 1000
const iterations = 100_000_000;
let seenAll = 0;
let missing = 0;
for (let i = 0; i <iterations; i++) {
let seen = Array(nrOfOptions).fill(false)
for (let s = 0; s < samples; s++) {
let val = Math.floor(Math.random() * nrOfOptions)
seen[val] = true
}
if (seen.every(x => x)) {
seenAll++
} else {
missing++;
}
if (i % 1_000_000 === 0) {
console.log({ i, seenAll, missing })
}
}
console.log({ seenAll, missing });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment