Home > Web Front-end > JS Tutorial > Javascript generates random numbers in a specified range_javascript skills

Javascript generates random numbers in a specified range_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 18:56:30
Original
917 people have browsed it

But after a little hard work, I finally figured it out, and the problem was naturally solved.
Then I wrote a formula, which should make this usage disappear. Formula:
1 . Starting from 1 to any value
linenum
parseInt(Math.random()*upper limit 1);
2. Starting from any value to any value
linenum
parseInt(Math.random ()*(upper limit - lower limit 1) lower limit);
The above formula uses parseInt(), so you need to add 1; if you use Math.ceil(), you don’t need to add 1. I am used to writing like this...
Directory:
1. Demonstration 1 (directly perform the operation of generating random numbers)
2. Demonstration 2 (write as a function to perform the operation of generating random numbers)
1. Demonstration 1 (directly perform the operation of generating random numbers) )
linenum

1-10:

11-20:

1-100:

51-100:


2. Demonstration 2 (written as a function to generate random numbers)
linenum

1-10:

11-20:

1-100:

51-100:

Related labels:
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 Issues
What are JavaScript hook functions?
From 1970-01-01 08:00:00
0
0
0
What is JavaScript garbage collection?
From 1970-01-01 08:00:00
0
0
0
c++ calls javascript
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template