Last active
December 17, 2015 23:29
-
-
Save Radnen/5689619 to your computer and use it in GitHub Desktop.
A seed based random number generator for your JS application. (Made for the Sphere Game Engine).
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
function Random(seed) { | |
const MAX = 2147483647; | |
const MULT = 48271; | |
const Q = Math.floor(MAX / MULT); | |
const R = Math.floor(MAX % MULT); | |
this.seed = seed || Date.now(); | |
this.next = function() { | |
var t = MULT * (this.seed % Q) - R * (this.seed / Q); | |
this.seed = (t > 0) ? t : t + MAX; | |
return (this.seed / MAX); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment