How to use javascript random method

藏色散人
Release: 2021-11-01 15:41:12
Original
2535 people have browsed it

javascript random method is used to return a random number between 0 and 1. Its usage syntax is such as "Math.random()", and the return value is a pseudo-random number between 0.0 and 1.0. .

How to use javascript random method

The operating environment of this article: Windows 7 system, JavaScript version 1.8.5, DELL G3 computer.

How to use javascript random method?

JavaScript random() method

Definition and usage

random() method can return a value between 0 ~ 1 random number.

Syntax

Math.random()
Copy after login

Return value

A pseudo-random number between 0.0 ~ 1.0.

Example

In this example, we will get a random number between 0 and 1:

<script type="text/javascript">
document.write(Math.random())
</script>
Copy after login

Output:

0.8187371959444101
Copy after login

Recommended Study: "javascript basic tutorial"

The above is the detailed content of How to use javascript random method. 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