Last active
August 29, 2015 14:23
-
-
Save jscari/ad0a939341cb53d9f86b 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
/** | |
A pseudo random integer between 0 and MAX_VALUE according to a number n, | |
returns always the same pseudo random number when giving the same n and MAX_VALUE | |
*/ | |
function pseudoRandomLCG(n, MAX_VALUE){ | |
var a = 25214903917; var c = 11; | |
var m = Math.pow(2,32); | |
var x = 0; | |
for(var i = 0;i<n;i++){ | |
x = (a+x*c) %m; | |
} | |
var rand = x % MAX_VALUE; | |
return rand; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment