Skip to content

Instantly share code, notes, and snippets.

@GUIEEN
Created February 1, 2019 08:27
Show Gist options
  • Save GUIEEN/09093d0e2fc8b9f6ef5252f4baf5c9ba to your computer and use it in GitHub Desktop.
Save GUIEEN/09093d0e2fc8b9f6ef5252f4baf5c9ba to your computer and use it in GitHub Desktop.
function uuid()
{
var seed = Date.now();
if (window.performance && typeof window.performance.now === "function") {
seed += performance.now();
}
var uuid = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
var r = (seed + Math.random() * 16) % 16 | 0;
seed = Math.floor(seed/16);
return (c === 'x' ? r : r & (0x3|0x8)).toString(16);
});
return uuid;
}
// https://stackoverflow.com/questions/105034/create-guid-uuid-in-javascript
var uniqueId = Math.random().toString(36).substring(2)
+ (new Date()).getTime().toString(36);
function generateGuid() {
var result, i, j;
result = '';
for(j=0; j<32; j++) {
if( j == 8 || j == 12 || j == 16 || j == 20)
result = result + '-';
i = Math.floor(Math.random()*16).toString(16).toUpperCase();
result = result + i;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment