shortid
Version:
Amazingly short non-sequential url-friendly unique id generator.
22 lines (17 loc) • 522 B
JavaScript
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;
;