Created
July 29, 2014 20:40
-
-
Save AaronHolbrook/e7dda3b12f88a07e290e to your computer and use it in GitHub Desktop.
Testing JS's random number distribution
This file contains hidden or 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
// 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