js生成某个范围的随机数

//生成[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);

  



posted @ 2017-03-07 17:45  loewe0202  阅读(168)  评论(0编辑  收藏  举报