-
-
Save JokingChicken/6de579cf3f65dbdac78efa55bef6b7d4 to your computer and use it in GitHub Desktop.
generate random UUIDs
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 b( | |
a // placeholder | |
){ | |
return a // if the placeholder was passed, return | |
? ( // a random number from 0 to 15 | |
a ^ // unless b is 8, | |
Math.random() // in which case | |
* 16 // a random number from | |
>> a/4 // 8 to 11 | |
).toString(16) // in hexadecimal | |
: ( // or otherwise a concatenated string: | |
[1e7] + // 10000000 + | |
-1e3 + // -1000 + | |
-4e3 + // -4000 + | |
-8e3 + // -80000000 + | |
-1e11 // -100000000000, | |
).replace( // replacing | |
/[018]/g, // zeroes, ones, and eights with | |
b // random hex digits | |
) | |
} |
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 b(a){return a?(a^Math.random()*16>>a/4).toString(16):([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,b)} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment