JavaScript Math.random() built-in function
random function return value
Returns a pseudorandom number between 0 and 1, possibly 0 but always less than 1, [0,1)
random function example
//return random number
document.write(Math.random());
//Return a random number from 10-20
document.write(Math.random()*(20-10)+10);
//The formula that returns a random number in the specified range (between mn)
document.write(Math.random()*(nm)+m);
Based on time, random numbers can also be generated
Copy the code code 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()%43; //This will generate an integer from 0 to 42 based on the current time.