Last active
December 14, 2020 08:27
-
-
Save IamManchanda/146feb8b14aa550d645098d467b2880a to your computer and use it in GitHub Desktop.
Create your own Universally Unique Identifier (UUID) - v4
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 uuidv4() { | |
const init = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"; | |
return init.replace(/[xy]/g, (c) => { | |
const r = Math.random() * 16 | 0; | |
const v = c == 'x' ? r : (r & 0x3 | 0x8); | |
return v.toString(16); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment