Created
June 3, 2020 12:39
-
-
Save doxas/614f0659b16f1098c782ac49b7b45fe1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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