Wednesday, January 26, 2011

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);

0 comentarii: