rng.js 549 B

123456789101112131415161718192021222324
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = rng;
  6. var _crypto = _interopRequireDefault(require("crypto"));
  7. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  8. const rnds8Pool = new Uint8Array(256); // # of random values to pre-allocate
  9. let poolPtr = rnds8Pool.length;
  10. function rng() {
  11. if (poolPtr > rnds8Pool.length - 16) {
  12. _crypto.default.randomFillSync(rnds8Pool);
  13. poolPtr = 0;
  14. }
  15. return rnds8Pool.slice(poolPtr, poolPtr += 16);
  16. }