js generates random numbers within a certain range

王林
Release: 2020-05-21 09:27:57
forward
2957 people have browsed it

js generates random numbers within a certain range

You can use the random() method, which returns a random number between 0 ~ 1.

The specific code is as follows:

//生成最小min到最大max的随机数 function random(min,max){ if(min > max){ var ls = min; min = max; max = ls; } return Math.floor(Math.random() * (max-min+1) ) + min; }
Copy after login

Recommended tutorial:js entry tutorial

The above is the detailed content of js generates random numbers within a certain range. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:cnblogs.com
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!