Skip to content

Instantly share code, notes, and snippets.

@jscari
Last active August 29, 2015 14:23
Show Gist options
  • Save jscari/ad0a939341cb53d9f86b to your computer and use it in GitHub Desktop.
Save jscari/ad0a939341cb53d9f86b to your computer and use it in GitHub Desktop.
/**
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