1.Math.min()/Math.max() (最小值和最大值)
console.log(Math.min(1, 2, 3, 4, 5)); //1
console.log(Math.max(1, 2, 3, 4, 5)); //5
若希望是以数组的方式传入的话可以使用apply()方法
console.log(Math.max.apply(null, [1, 2, 3, 4, 5])); //返回5
2.Math.ceil()/Math.floor() (向上取整和向下取整)
console.log(Math.ceil(5.01)); //6
console.log(Math.floor(5.99)); //5
3.Math.round() (四舍五入)
console.log(Math.round(5.5)); //6
console.log(Math.round(5.4)); //5
4.Math.random() (0-1之间的随机数)
console.log(Math.random()) // 0<= 返回值 <1
例:0-5之间的随机整数
console.log(Math.floor(Math.random() * (5 + 1))) //0-5之间的随机整数
公式:min+Math.floor(Math.random()*(Max-min+1))