JavaScript Random

In JavaScirpt Math.random() is used to returns random number between 0 (inclusive) and 1 (exclusive) in JavaScript.

Example of Math.random()

In this example math.random() method to display the random number between 0 to 1.

<script type = "text/javascript">
document.write("Random value is: " + Math.random());
</script>                  
        

Output of above code


Example of JavaScript Random Integers

In this example Math.random() used with Math.floor() to display random integers.

<script type = "text/javascript"> document.write("returns a random integer from 0 to 9: <br/> " + Math.floor(Math.random() * 10)); </script>

Output of above code








The Best

Comment here

If you have any query, if you want to know something about any of technical course related to computer science field, if you have any suggestion about relevant to uploaded content or if you anything wrong here (any mistake in content) than please contact us. Keep in mind, comment should be according to community guidelines.