Skip to content

Instantly share code, notes, and snippets.

@randhirraj3130
Created December 20, 2016 07:57
Show Gist options
  • Save randhirraj3130/6f8c61e3baa391e9b3eed17dc7eb85ea to your computer and use it in GitHub Desktop.
Save randhirraj3130/6f8c61e3baa391e9b3eed17dc7eb85ea to your computer and use it in GitHub Desktop.
How to generate system unique UUID
function uuid()
{
var char = '0123456789abcdef'.split('');
var uuid = [], rnd = Math.random, r;
uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
uuid[14] = '4'; // version 4
for (var i = 0; i < 36; i++)
{
if (!uuid[i])
{
r = 0 | rnd()*16;
uuid[i] = char[(i == 19) ? (r & 0x3) | 0x8 : r & 0xf];
}
}
return uuid.join('');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment