Created
August 8, 2012 19:06
-
-
Save justinbowes/3297665 to your computer and use it in GitHub Desktop.
LCG RNG
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
// 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