Skip to content

Instantly share code, notes, and snippets.

@anonymoustafa
Created April 23, 2022 14:20
Show Gist options
  • Save anonymoustafa/3676b3f88f37d15ebb699637abdf2234 to your computer and use it in GitHub Desktop.
Save anonymoustafa/3676b3f88f37d15ebb699637abdf2234 to your computer and use it in GitHub Desktop.
iam_vee challenge
// link to the main tweet: https://twitter.com/iam_vee/status/1517357609170386944?s=20&t=MN3UgYbDae5NCTSoeh5mzg
var sum = 0, counter = 0,
maxTries = 1000_000;
for (let i = 1; i <= maxTries; i++) {
counter++;
while (1) {
sum++;
if (gimmeRand1to6() == 6) break;
}
}
let probabilty = sum / maxTries;
console.log(`the probabilty of happening 6 is almost equal to ${probabilty} after ${counter} trials.`);
function gimmeRand1to6() {
return (Math.floor(Math.random() * 6)+1);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment