PRNG.js 399 B

1234567891011
  1. // Park-Miller-Carta Pseudo-Random Number Generator
  2. // https://github.com/pnitsch/BitmapData.js/blob/master/js/BitmapData.js
  3. var PRNG = function () {
  4. this.seed = 1;
  5. this.next = function() { return (this.gen() / 2147483647); };
  6. this.nextRange = function(min, max) { return min + ((max - min) * this.next()) };
  7. this.gen = function() { return this.seed = (this.seed * 16807) % 2147483647; };
  8. };