Home  >  Article  >  Web Front-end  >  How to use javascript random method

How to use javascript random method

藏色散人
藏色散人Original
2021-11-01 15:41:122529browse

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

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>

Output:

0.8187371959444101

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!

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