JS generates random numbers in the following ways
1. JavaScript math.random () built-in functions
The random function returns a value
Returns the pseudo-random number between 0 and 1, which may be 0, but is always less than 1,[0,1
Example of the random function
return random number
document.write (Math.random ());
Returns a random number of 10-20
document.write (Math.random () * (20-10) +10);
Returns the formula for a specified range of random numbers (between m-n)
document.write (Math.random () * (N-M) +m);
2, Math.ceil (n); Returns the smallest integer greater than or equal to N.
With Math.ceil (Math.random () *10), a random integer of 1 to 10 is obtained, with a minimum probability of 0 being taken.
3, Math.Round (n); Returns the value of an integer after n rounding.
With Math.Round (Math.random ()), a random integer from 0 to 1 can be obtained evenly.
With Math.Round (Math.random () *10), the basic equalization is obtained from 0 to 10 of random integers, where the minimum 0 and maximum 10 are obtained.
Less than half the odds.
4, Math.floor (n); Returns the largest integer less than or equal to N.
With Math.floor (Math.random () *10), a random integer from 0 to 9 can be obtained evenly.
5, based on time, can also generate random numbers
var now=new Date ();
var number = Now.getseconds (); This will result in a 0 to 59 integer based on the current time.
var now=new Date ();
var number = Now.getseconds ()%43; This will result in a 0 to 42 integer based on the current time.
JS Random number