Skip to content

Instantly share code, notes, and snippets.

@justinbowes
Created August 8, 2012 19:06
Show Gist options
  • Save justinbowes/3297665 to your computer and use it in GitHub Desktop.
Save justinbowes/3297665 to your computer and use it in GitHub Desktop.
LCG RNG
// Implements an LCG RNG.
var Random = function Random(seed) {
this.term = (typeof seed !== 'undefined' ? seed : new Date().getTime());
this.multiplier = 60969; // carefully chosen
this.modulus = Math.pow(2, 32);
this.increment = 1;
};
Random.prototype.randInt = function(range) {
this.term = (this.term * this.multiplier + this.increment) % this.modulus;
return this.term % range;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment