Home > Web Front-end > JS Tutorial > Random example of random function to generate random numbers in js_javascript skills

Random example of random function to generate random numbers in js_javascript skills

WBOY
Release: 2016-05-16 17:07:56
Original
1450 people have browsed it

JavaScript Math.random() built-in function
random function return value
returns a pseudo-random number between 0 and 1, which may be 0, but is always less than 1, [0,1)
Random function example
//Returns a random number
document.write(Math.random());
//Returns a random number between 10-20
document.write(Math.random ()*(20-10) 10);
//Return the formula for a random number in the specified range (between m-n)
document.write(Math.random()*(n-m) m);
Based on time, random numbers can also be generated

Copy code The code is as follows:

var now=new Date();
var number = now.getSeconds(); //This will generate an integer from 0 to 59 based on the current time.
var now=new Date();
var number = now.getSeconds()C; //This will generate an integer from 0 to 42 based on the current time.
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