Skip to content

Instantly share code, notes, and snippets.

@AaronHolbrook
Created July 29, 2014 20:40
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 AaronHolbrook/e7dda3b12f88a07e290e to your computer and use it in GitHub Desktop.
Save AaronHolbrook/e7dda3b12f88a07e290e to your computer and use it in GitHub Desktop.
Testing JS's random number distribution
// repl.it test: http://repl.it/WDj/
var keys = ["0", "1", "2"]
var keyCount = {
0: 0,
1: 0,
2: 0
};
function randGen( randArray ) {
return Math.floor( Math.random() * keys.length )
}
var reps = 1000000;
while ( reps >= 0 ) {
var temp_rand = randGen( keys );
keyCount[ temp_rand ] = keyCount[ temp_rand] + 1;
reps--;
}
console.log( keyCount );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment