1
0

prand.js 486 B

123456789101112131415161718192021
  1. "use strict";
  2. const assert = require("assert");
  3. /**
  4. * Creates a pseudo-random value generator. The seed must be an integer.
  5. */
  6. function Random(seed) {
  7. assert.equal(typeof seed, "number");
  8. this._seed = seed % 2147483647;
  9. if (this._seed <= 0) this._seed += 2147483646;
  10. }
  11. /**
  12. * Returns a 32-bit pseudo-random value.
  13. */
  14. Random.prototype.next = function () {
  15. this._seed = (this._seed * 16807) & 0xffffffff;
  16. return (this._seed - 1) | 0;
  17. };
  18. module.exports = Random;