How to use random in JavaScript

In this article we will discuss about how to use random() Method in JavaScript.
  • 2104

This is most important method of the Math object in JavaScript. This method is used to return the random value generated between the 0 and 1. Here is the following Syntax to use this method.

Syntax:

Math.random();

JavaScript Code:

<html>

<head>

    <title>JavaScript Math random() Method</title>

</head>

<body>

    <script type="text/javascript">

 

        var ranvalue = Math.random();

        document.write("First Random Value : " + ranvalue

);

 

        var ranvalue = Math.random();

        document.write("<br />Second Random Value : " +

ranvalue);

 

        var ranvalue = Math.random();

        document.write("<br />Third Random Value : " +

ranvalue);

 

        var ranvalue = Math.random();

        document.write("<br />Fourth Random Value : " +

ranvalue);

 

        var ranvalue = Math.random();

        document.write("<br />Fifth Random Value : " +

ranvalue);

    </script>

</body>

</html>

Output:

 java4.jpg

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.