You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

17 lines
438 B

4 years ago
  1. 'use strict';
  2. if (global.crypto && global.crypto.getRandomValues) {
  3. module.exports.randomBytes = function(length) {
  4. var bytes = new Uint8Array(length);
  5. global.crypto.getRandomValues(bytes);
  6. return bytes;
  7. };
  8. } else {
  9. module.exports.randomBytes = function(length) {
  10. var bytes = new Array(length);
  11. for (var i = 0; i < length; i++) {
  12. bytes[i] = Math.floor(Math.random() * 256);
  13. }
  14. return bytes;
  15. };
  16. }