1.Math.random(); 结果为0-1间的一个随机数(包括0,不包括1)
Math.random(); 结果为0-1间的一个随机数(包括0,不包括1) [html] view plaincopyprint?


2.Math.floor(num); 参数num为一个数值,函数结果为num的整数部分(返回小于等于n的最大整数)。


Math.floor(num); 参数num为一个数值,函数结果为num的整数部分(返回小于等于n的最大整数)。[html] view plaincopyprint?


3.Math.round(num); 参数num为一个数值,函数结果为num四舍五入后的整数。


Math.round(num); 参数num为一个数值,函数结果为num四舍五入后的整数。[html] view plaincopyprint?


4.Math.ceil(n); 返回大于等于n的最小整数。


Math.ceil(n); 返回大于等于n的最小整数。[html] view plaincopyprint?


5.Math.ceil(Math.random()*10);时,主要获取1到10的随机整数,取0的几率极小。


Math.ceil(Math.random()*10);时,主要获取1到10的随机整数,取0的几率极小。[html] view plaincopyprint?


6.Math.round(Math.random());可均衡获取0到1的随机整数。


Math.round(Math.random());可均衡获取0到1的随机整数。[html] view plaincopyprint?


7.Math.round(Math.random()*10);时,可基本均衡获取0到10的随机整数,其中获取最小值0和最大值10的几率少一半。


Math.round(Math.random()*10);时,可基本均衡获取0到10的随机整数,其中获取最小值0和最大值10的几率少一半。[html] view plaincopyprint?


8.Math.floor(Math.random()*10);时,可均衡获取0到9的随机整数。

09-04 14:08