PRNG.js 424 B

1234567891011121314151617181920212223
  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() {
  6. return ( this.gen() / 2147483647 );
  7. };
  8. this.nextRange = function( min, max ) {
  9. return min + ( ( max - min ) * this.next() )
  10. };
  11. this.gen = function() {
  12. return this.seed = ( this.seed * 16807 ) % 2147483647;
  13. };
  14. };