Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@josser
Last active March 4, 2016 15:32
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 josser/66b895c8bb3826ef6d89 to your computer and use it in GitHub Desktop.
Save josser/66b895c8bb3826ef6d89 to your computer and use it in GitHub Desktop.
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);
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