Skip to content

Instantly share code, notes, and snippets.

@eppfel
Created April 21, 2017 19:12
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 eppfel/a1fd63aafcfcb9861a70e59bd315666a to your computer and use it in GitHub Desktop.
Save eppfel/a1fd63aafcfcb9861a70e59bd315666a to your computer and use it in GitHub Desktop.
var throwDice = function () {
return Math.floor(Math.random() * (6)) + 1;
};
var results = [0,0,0,0,0,0];
var iterations = 10000000;
for (var i = 0; i < iterations; i++) {
results[throwDice()-1]++;
}
for (var i = 0; i < results.length; i++) {
var percentage = results[i] / iterations * 100;
println((i+1) + ': ' + percentage + '%\n');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment