1. Math.ceil()
用作向上取整。
2. Math.floor()
用作向下取整。
3. Math.round()
我們數學中常用到的四捨五入取整。
4.Math.random()
取[0, 1)之間的隨機小數。
(1)Math.ceil(Math.random()*10);
[0,10] 主要獲取1到10的隨機整數,取0的機率極小
(2)Math.floor(Math.random()*10);
[0, 9] 可均衡獲取0到9的隨機整數。
(3)Math.round(Math.random());
[0,1]可均衡獲取0到1的隨機整數。
(4)Math.round(Math.random()*10);
[0, 10]可基本均衡獲取0到10的隨機整數,其中獲取最小值0和最大值10的機率少一半。