1. Summary of Math

The Math object is not a constructor, but a concrete object with properties and methods of mathematical constants and functions. Math related operations (absolute values, roundings, maxima, and so on) can use members of Math.

Property, method name function
Math.PI PI
Math.floor() Take down the whole
Math.ceil() Take up the whole
Math.round() Note that the nearest rounded version is -3.5 and the result is -3
Math.abs() The absolute value
Math.max()/Math.min() Find the maximum and minimum
Math.random() Gets a random value in the range [0,1)

Note: The above method must be used with parentheses

2. Random method random()

The random() method returns a random decimal in the range [0, 1], where 0 <= x < 1

Gets a random integer in the specified range:

Get a random integer between two numbers, including two numbers

function getRandom(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min; 
}
Copy the code