Skip to content

Instantly share code, notes, and snippets.

@Radnen
Last active December 17, 2015 23:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Radnen/5689619 to your computer and use it in GitHub Desktop.
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).
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