Home > Article > Web Front-end > Random example of random function to generate random numbers in js_javascript skills
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