Generate a new Guid in JavaScript

As easy as that 🙂

// Generate new Guid
function Hexa4()
{
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}
function GenerateGuid()
{
return (Hexa4()+Hexa4()+”-“+Hexa4()+”-“+Hexa4()+”-“+Hexa4()+”-“+

Hexa4()+Hexa4()+Hexa4()).toUpperCase();
}

// USE
var guid = GenerateGuid();
alert(guid);

Leave a comment

Your email address will not be published. Required fields are marked *