123456789101112131415161718192021 |
- 'use strict';
- var crypto = typeof window === 'object' && (window.crypto || window.msCrypto); // IE 11 uses window.msCrypto
- var randomByte;
- if (!crypto || !crypto.getRandomValues) {
- randomByte = function(size) {
- var bytes = [];
- for (var i = 0; i < size; i++) {
- bytes.push(Math.floor(Math.random() * 256));
- }
- return bytes;
- };
- } else {
- randomByte = function(size) {
- return crypto.getRandomValues(new Uint8Array(size));
- };
- }
- module.exports = randomByte;
|