Home > Web Front-end > JS Tutorial > body text

Javascript generates random numbers in a specified range_javascript skills

WBOY
Release: 2016-05-16 18:56:30
Original
874 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:
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