JavaScript returns a random number between 0 and 1

  • 2020-05-26 07:49:55
  • OfStack

This example shows how JavaScript returns random Numbers between 0 and 1. Share with you for your reference. The details are as follows:

The random method of JavaScript's Math object returns a random number between 0 and 1


<!DOCTYPE html>
<html>
<body>
<p id="demo">
Click the button to display a random number.
</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction()
{
document.getElementById("demo").innerHTML=Math.random();
}
</script>
</body>
</html>

I hope this article has been helpful to your javascript programming.


Related articles: