How to generate a random number in javascript based on mathrandom _ javascript technique

Source: Internet
Author: User
This article describes how to generate a random number in the javascript random number mathrandom to generate a random number in the specified range. Since math. random generates a pseudo random number, it will be processed later. If you are interested in the random number mathrandom, learn about it. Today, a friend asks me how JavaScript generates a random number in a specified range. Math. random () is used to generate random numbers. However, the general reference manual does not explain how to use this method to generate random numbers within a specified range. This time I will introduce Math. random () in detail and how to use it to generate random numbers within the specified range.

W3school's random () tutorial

Definition and usage

The random () method returns a value ranging from 0 ~ A random number between 1.

Syntax

Math. random ()

Return value

0.0 ~ A pseudo-random number between 1.0.

Instance

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.