Last active
March 4, 2016 15:32
-
-
Save josser/66b895c8bb3826ef6d89 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
var iterations = 100000000; | |
var stats = { | |
win: 0, | |
loose: 0 | |
} | |
function generatePrises() { | |
var initial = [0, 0, 0]; | |
initial[Math.floor(Math.random() * 3)] = 1; | |
return initial; | |
} | |
function chooseRandom() { | |
return Math.floor(Math.random() * 3); | |
} | |
for (i = 0; i<=iterations; i++) { | |
var prises = generatePrises(); | |
var choose = chooseRandom(); | |
if (prises[choose] == 1) { | |
stats.win++; | |
} else { | |
stats.loose++; | |
} | |
} | |
console.log(stats, stats.win / iterations * 100); |
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
var iterations = 100000000; | |
var stats = { | |
win: 0, | |
loose: 0 | |
} | |
function generatePrises() { | |
var initial = [0, 0, 0]; | |
initial[Math.round(Math.random() * 2)] = 1; | |
return initial; | |
} | |
function chooseRandom() { | |
return Math.round(Math.random() * 2); | |
} | |
for (i = 0; i<=iterations; i++) { | |
var prises = generatePrises(); | |
var choose = chooseRandom(); | |
if (prises[choose] == 1) { | |
stats.win++; | |
} else { | |
stats.loose++; | |
} | |
} | |
console.log(stats, stats.win / iterations * 100); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment