Created
December 20, 2016 07:57
-
-
Save randhirraj3130/6f8c61e3baa391e9b3eed17dc7eb85ea to your computer and use it in GitHub Desktop.
How to generate system unique UUID
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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