javascript获取随机整数
来源:岁月联盟
时间:2008-10-07
Math.rand = function(l,u)
{
return Math.floor((Math.random() * (u-l+1))+l);
}
Math.prototype.rand = function(l,u)
{
return Math.floor((Math.random() * (u-l+1))+l);
}
Sample: Math.rand(1,10)
大家说这两个方法都可以吗? 那个是正确的做法?呵呵,测试一下就知道了:)