码迷,mamicode.com
首页 > Web开发 > 详细

js生成某个范围的随机数

时间:2017-03-07 19:02:51      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:highlight   div   class   ceil   blog   pre   htm   floor   rand   

//生成[min,max)的值 parseInt
var RandomNum = parseInt(Math.random() * (21 - 15) + 15);

// 生成[min,max]的值 Math.round 四舍五入
var RandomNum = Math.round(Math.random() * (21 - 15) + 15);

//生成(min,max]的值 Math.ceil() 向上取整
var RandomNum = Math.ceil(Math.random() * (21 - 15) + 15);

//生成[min,max)的值 Math.floor() 向下取整
var RandomNum = Math.floor(Math.random() * (21 - 15) + 15);

  



js生成某个范围的随机数

标签:highlight   div   class   ceil   blog   pre   htm   floor   rand   

原文地址:http://www.cnblogs.com/loewe0202/p/6515983.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!