Math.random() : random : Math JAVASCRIPT TUTORIALS


JAVASCRIPT TUTORIALS » Math » random »

 

Math.random()









Syntax








math.random(num)



The random() method of the Math object is used to obtain a random number between values 0 and 1.












<html>
    <body>
    <script language="JavaScript">
    <!--
    function doMath(){
        var result = Math.random();
        document.form1.answer.value = result;
    }
    -->
    </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>







HTML code for linking to this page:

Follow Navioo On Twitter

JAVASCRIPT TUTORIALS

 Navioo Math
» random