Skip to content

Instantly share code, notes, and snippets.

@ek
Created January 19, 2016 02:12
Show Gist options
  • Save ek/a45de2d7d6d31a71872f to your computer and use it in GitHub Desktop.
Save ek/a45de2d7d6d31a71872f to your computer and use it in GitHub Desktop.
generate a unique UUID using Javascript Math.random
// 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