Last active
December 22, 2017 20:45
-
-
Save Kroid/4952ac8605a81d492e5a1199a6930948 to your computer and use it in GitHub Desktop.
This file contains 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
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