Skip to content

Instantly share code, notes, and snippets.

@nealnote
Created August 5, 2014 06:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nealnote/8056c55f242bc83dd7c3 to your computer and use it in GitHub Desktop.
Save nealnote/8056c55f242bc83dd7c3 to your computer and use it in GitHub Desktop.
guid.js
//https://github.com/jeromegn/Backbone.localStorage/blob/master/backbone.localStorage.js#L27
// Generate four random hex digits.
function S4() {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
};
// Generate a pseudo-GUID by concatenating random hexadecimal.
function guid() {
return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment