Skip to content

Instantly share code, notes, and snippets.

@marlonlom
Created November 20, 2017 02:01
Show Gist options
  • Save marlonlom/8a0dff744f0e3f8191ca00e7ef13f245 to your computer and use it in GitHub Desktop.
Save marlonlom/8a0dff744f0e3f8191ca00e7ef13f245 to your computer and use it in GitHub Desktop.
Gist for javascript function that creates universally unique identifier (UUID), which is a 128-bit number used to identify information in computer systems.
console.log(uuid());
function uuid() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0, 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