当前位置:首页 > 设计在线 > 网页设计 > Dhtml > javascript获取随机整数

javascript获取随机整数

点击次数:59 次 发布日期:2008-11-24 21:00:23 作者:源代码网
源代码网推荐

最近发现两个重写Math.round方法的实现:

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)

  大家说这两个方法都可以吗? 那个是正确的做法?呵呵,测试一下就知道了:)

本文作者:
源代码网供稿.
网友评论 (0)
会员中心
设计在线
本站推荐
设计在线之精华