Created
October 30, 2016 18:08
-
-
Save SoftwareDevPro/984b10685e3c83fd75f025541f9c37f5 to your computer and use it in GitHub Desktop.
Creates a UUID and returns it.
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
# Filed under: uuid, id, random | |
### | |
a: placeholder | |
### | |
b = (a) -> | |
### | |
if the placeholder was passed, return a random number from 0 to 15 unless b | |
is 8, in which case a random number from 8 to 11 in hexadecimal or | |
otherwise a concatenated string: 10000000 + -1000 + -4000 + -80000000 + | |
-100000000000, replacing zeroes, ones, and eights with random hex digits | |
### | |
if a | |
(a ^ Math.random() * 16 >> a / 4).toString(16) | |
else | |
([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