How do you generate a random number from JavaScript?

John Zukowski

You can either get the time and manipulate that to give you something random or call Math.random():

<script language="JavaScript"><!--
today = new Date();
num = today.getTime();
num = Math.round(Math.abs(Math.sin(num) * 1000000));

rand = Math.random()*1000000;
randInt = Math.floor(rand);
// --></script>
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact