JavaScript Ninja - Better UUID Using Chrome's Crypto

Posted at

(function(temp, y) {
crypto.getRandomValues(new Uint64Array(10)).forEach(function(n) {
temp.push(n.toString(16))
});

temp = temp.join(''); /* long string */
temp = temp.replace(/.*(........)..(....)..(...)..(...)..(............).*/, "$1-$2-4$3-" + y + "$4-$5") /* set format */

return temp;
}(
[]
, [8, 9, 'a', 'b'][~~(Math.random() * 4)] /* choose either one */
));


there is no reason for the ".." between groups :)