Home > Article > Web Front-end > Does the return value of random method in javascript contain 0?
In JavaScript, the return value of the random() method contains 0; the random() method can return a random number between 0 and 1. The returned result does not contain 1, but contains 0. The syntax is "Math .random()".
The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.
The random() method can return a random number between 0 (inclusive) ~ 1 (exclusive).
The syntax is:
Math.random()
Return value:
A pseudo-random number between 0.0 ~ 1.0 (not included).
The example is as follows:
<html> <head> <meta charset="utf-8"> <title>123</title> </head> <body> <p id="demo">点击按钮显示一个 1 到 100 的随机数。</p> <button onclick="myFunction()">点我</button> <script> function myFunction(){ var x=document.getElementById("demo") x.innerHTML=Math.floor((Math.random()*100)+1); } </script> </body> </html>
Output result:
Related recommendations: javascript learning tutorial
The above is the detailed content of Does the return value of random method in javascript contain 0?. For more information, please follow other related articles on the PHP Chinese website!