Wednesday, February 4, 2009

javascript function for generate unique random number

I created a javascript function for generate unique random number. for this function i take object of date and call funciton of getTime() which return milliseconds since 970/01/01 and i also add some random numeric value between 0 to 999 from make it Random.

code snips is as

[script language="javascript"]

function UniqRanDomNumber()


var d = new Date();

var randomnumber = Math.floor(Math.random()*1001);

var randomnumber = d.getTime() + randomnumber;


//alert(randomnumber.toString().substring(6,13)); // If we want to remove right side number whihc are prefixed

document.getElementById("lbl").innerHTML = randomnumber;

return false;



lbl is id of label where we want to show the uniq random nubmer.

HelpOnDesk Team

No comments: