Can someone please explain the following code snippet to generate UUID 4 and is it meeting the specs and what are the specs in short?
var randomBytes = crypto.randomBytes(16);
randomBytes[6] = (randomBytes[6] & 0x0f) | 0x40; // whats the use
randomBytes[8] = (randomBytes[8] & 0x3f) | 0x80; // same?
randomBytes = randomBytes.toString('hex').match(/(.{8})(.{4})(.{4})(.{4})(.{12})/); // what's happening here?
randomBytes.shift(); // shifting for?
return randomBytes.join('-');
via Devyiweid
No comments:
Post a Comment