Skip to content

Instantly share code, notes, and snippets.

@Kroid

Kroid/simulation.js

Last active Dec 22, 2017
Embed
What would you like to do?
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
You can’t perform that action at this time.