Home > Web Front-end > Front-end Q&A > Does the return value of random method in javascript contain 0?

Does the return value of random method in javascript contain 0?

WBOY
Release: 2022-03-02 16:33:23
Original
2552 people have browsed it

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

Does the return value of random method in javascript contain 0?

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

Does the return value of the random method in JavaScript include 0?

The random() method can return a random number between 0 (inclusive) ~ 1 (exclusive).

The syntax is:

Math.random()
Copy after login

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>
Copy after login

Output result:

Does the return value of random method in javascript contain 0?

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template