Skip to content

Instantly share code, notes, and snippets.

@doxas
Created June 3, 2020 12:39
Show Gist options
  • Save doxas/614f0659b16f1098c782ac49b7b45fe1 to your computer and use it in GitHub Desktop.
Save doxas/614f0659b16f1098c782ac49b7b45fe1 to your computer and use it in GitHub Desktop.
function uuid(){
// https://github.com/GoogleChrome/chrome-platform-analytics/blob/master/src/internal/identifier.js
const chars = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.split('');
for(let i = 0, j = chars.length; i < j; i++){
switch(chars[i]){
case 'x':
chars[i] = Math.floor(Math.random() * 16).toString(16);
break;
case 'y':
chars[i] = (Math.floor(Math.random() * 4) + 8).toString(16);
break;
}
}
return chars.join('');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment