Math.random() method returns a random number greater than or equal to 0 and less than 1. For some sites, this method is very practical, because it can be used to randomly display some famous quotes and news events.
1. Obtain a random number from continuous integers
Value = Math.floor(Math.random() * total number of possible values first possible value)
Example: Generate random numbers from 1-10
Write a function that generates random numbers from startNumber to endNumber
2. Obtain a random number from non-adjacent integers
2.1 Obtain a random number from two non-adjacent integers
Example: Randomly generate a number between 2 or 4
2.2 Generate a random number from multiple non-adjacent integers
Combined with the function parameter array, you can write a function that generates a random value among multiple non-adjacent integers
It is troublesome to enter so many parameters every time. You can rewrite the function
Or without changing the original method, you can use the apply() method to pass array parameters
For information about the use of the apply method, please see http://www.jb51.net/article/42705.htm
The above is the entire content of this article, I hope you all like it.