Home > Article > Web Front-end > Will the math.random() method in javascript randomize to 1?
In JavaScript, the "math.random()" method will not randomize to 1; this method is used to return a random number between 0 and 1. The returned random number may contain 0, but Not containing 1, 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()
The returned result is a pseudo-random number between
0.0 ~ 1.0 (exclusive).
The example is as follows:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>123</title> </head> <body> <p id="demo">点击按钮显示一个随机数</p> <button onclick="myFunction()">点我</button> <script> function myFunction(){ document.getElementById("demo").innerHTML=Math.random(); } </script> </body> </html>
Output result:
Related recommendations: javascript learning tutorial
The above is the detailed content of Will the math.random() method in javascript randomize to 1?. For more information, please follow other related articles on the PHP Chinese website!