Generate random URL : random « Math « JavaScript Tutorial






<HTML>

<HEAD>

<SCRIPT language="JavaScript">
<!--

var rand_url= new Array()
rand_url[0]="http://www.java2s.com";
rand_url[1]="http://www.java2s.com";
rand_url[2]="http://www.java2s.com";
rand_url[3]="http://www.java2s.com";
rand_url[4]="http://www.java2s.com";

var rand_num= Math.floor(Math.random()*5);

//-->
</SCRIPT>

</HEAD>

<BODY>

<H2>List of Cars:</H2>

<SCRIPT language="JavaScript">
<!--
 document.write("<A HREF='"+rand_url[rand_num]+"'>"+rand_url[rand_num]+"</A>");
//-->
</SCRIPT>

</BODY>

</HTML>








9.21.random
9.21.1.Math.random()
9.21.2.Use Math.random to generate random number
9.21.3.Math.round a random number
9.21.4.Generate a random integer between 2 and 10
9.21.5.Generate random URL
9.21.6.Generate random numbes in a range