Created
January 19, 2016 02:12
-
-
Save ek/a45de2d7d6d31a71872f to your computer and use it in GitHub Desktop.
generate a unique UUID using Javascript Math.random
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
// from alexmorleyfinch's comment on this thread: | |
// https://gist.github.com/gordonbrander/2230317#gistcomment-1618310 | |
var generateUniqueId = function(){ | |
function chr4(){ | |
return Math.random().toString(16).slice(-4); | |
}; | |
return chr4() + chr4() + | |
'-' + chr4() + | |
'-' + chr4() + | |
'-' + chr4() + | |
'-' + chr4() + chr4() + chr4(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment