August 1999
Intermediate to advanced
1488 pages
72h 53m
English
math.random(num)
The random() method of the Math object is used to obtain a random number between values 0 and 1.
Listing 6.170 shows how the random() method is used to calculate random numbers.
<html> <body> <script language="JavaScript"> <!–– Hide // function generates a random number between 0 & 1 function doMath(){ var result = Math.random(); document.form1.answer.value = result; } // End Hide ––> </script> <form name=form1> The random number is: <input type="text" name="answer" size=20> <input type="button" value="Calculate" onClick='doMath()'> <br> </form> </body> </html> ... |
Read now
Unlock full access