rng.js 440 B

1234567891011
  1. let getRandomValues;
  2. const rnds8 = new Uint8Array(16);
  3. export default function rng() {
  4. if (!getRandomValues) {
  5. if (typeof crypto === 'undefined' || !crypto.getRandomValues) {
  6. throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
  7. }
  8. getRandomValues = crypto.getRandomValues.bind(crypto);
  9. }
  10. return getRandomValues(rnds8);
  11. }