I came across this JavaScript function and I don’t understand quite what it’s doing, especially with the use of 0xF.
What does the 0xF do, exactly. It looks like a null nibble to me.
function()
{
var g = "";
for(var i = 0; i < 32; i++)
g += Math.floor(Math.random() * 0xF).toString(0xF)
return g;
}
0xF== 15. It’s simply hexadecimal notation.However, that snippet is not actually creating a GUID, it’s just stringing a bunch of random integers together. It’s not possible to create a GUID in JavaScript, because generating one requires parameters that the VM can’t access (network address, etc).
See also my answer to this question: How to create a GUID in Javascript?