JSFiddle - React, Tailwind, and code Playground
by kodisha
JavaScript
function _getRandomData() {
if (window && window.crypto && window.crypto.getRandomValues) {
return crypto.getRandomValues(new Uint8Array(1))[0] % 16;
} else {
return Math.random() * 16;
}
}
function generateUUID(placeholder) {
return placeholder
? (placeholder ^ _getRandomData() >> placeholder / 4).toString(16)
: ([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, generateUUID);
}
let u = new Map();
for (let i = 0; i <= 100_000; i+=1) {
const uuid=generateUUID();
if(!u.has(uuid)) {
u.set(uuid,true);
} else{
console.log('DUPLICATE UUID', uuid);
}
}
console.log('all done!');