Skip to content

Instantly share code, notes, and snippets.

@Kroid
Last active December 22, 2017 20:45
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 Kroid/4952ac8605a81d492e5a1199a6930948 to your computer and use it in GitHub Desktop.
Save Kroid/4952ac8605a81d492e5a1199a6930948 to your computer and use it in GitHub Desktop.
function round(bool) {
let answer = false;
if (Math.random() > 0.3) answer = true;
if (bool == answer) return 1;
return -1;
}
let result;
result = 0;
for (let i =0; i<10000; i++) {
result += round(true);
}
console.log(`always true: ${result}`);
result = 0;
for (let i =0; i<10000; i++) {
result += round(false);
}
console.log(`always false: ${result}`);
result = 0;
for (let i =0; i<10000; i++) {
let bool = false
if (Math.random() > 0.3) bool = true;
result += round(bool);
}
console.log(`70% true, 30% false: ${result}`);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment