Last active
July 5, 2024 14:01
-
-
Save TiddoLangerak/252ee6503351d3c50bc5054fa2416776 to your computer and use it in GitHub Desktop.
Simulate flakiness probability
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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