Home  >  Article  >  Web Front-end  >  Will the math.random() method in javascript randomize to 1?

Will the math.random() method in javascript randomize to 1?

WBOY
WBOYOriginal
2022-02-14 17:30:192899browse

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()".

Will the math.random() method in javascript randomize to 1?

The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.

Will the math.random() method in javascript be random to 1?

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:

Will the math.random() method in javascript randomize to 1?

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn