<SPAN>1.Math.random(); 结果为0-1间的一个随机数(包括0,不包括1) </SPAN>
Math.random(); 结果为0-1间的一个随机数(包括0,不包括1) [html] view plaincopyprint?
<SPAN>
2.Math.floor(num); 参数num为一个数值,函数结果为num的整数部分(返回小于等于n的最大整数)。</SPAN>
Math.floor(num); 参数num为一个数值,函数结果为num的整数部分(返回小于等于n的最大整数)。[html] view plaincopyprint?
<SPAN>
3.Math.round(num); 参数num为一个数值,函数结果为num四舍五入后的整数。</SPAN>
Math.round(num); 参数num为一个数值,函数结果为num四舍五入后的整数。[html] view plaincopyprint?
<SPAN>
4.Math.ceil(n); 返回大于等于n的最小整数。</SPAN>
Math.ceil(n); 返回大于等于n的最小整数。[html] view plaincopyprint?
<SPAN>
5.Math.ceil(Math.random()*10);时,主要获取1到10的随机整数,取0的几率极小。</SPAN>
Math.ceil(Math.random()*10);时,主要获取1到10的随机整数,取0的几率极小。[html] view plaincopyprint?
<SPAN>
6.Math.round(Math.random());可均衡获取0到1的随机整数。</SPAN>
Math.round(Math.random());可均衡获取0到1的随机整数。[html] view plaincopyprint?
<SPAN>
7.Math.round(Math.random()*10);时,可基本均衡获取0到10的随机整数,其中获取最小值0和最大值10的几率少一半。</SPAN>
Math.round(Math.random()*10);时,可基本均衡获取0到10的随机整数,其中获取最小值0和最大值10的几率少一半。[html] view plaincopyprint?
<SPAN>
8.Math.floor(Math.random()*10);时,可均衡获取0到9的随机整数。</SPAN>
【js中Math之random,round,ceil,floor的用法总结】相关文章:
★ JavaScript中用于生成随机数的Math.random()方法
★ JavaScript中操作字符串之localeCompare()方法的使用
★ JavaScript中String.prototype用法
★ javascript中clipboardData对象用法
★ 浅谈JavaScript中的Math.atan()方法的使用
★ JavaScript中反正弦函数Math.asin()的使用简介