获取范围内的随机整数

function getRandomNumber(min,max){
  min = Math.ceil(min);  //向上取整
  max = Math.floor(max);  //向下取整  Math.round(num) 四舍五入
  return Math.floor(Math.random()*(max-min+1)+min)
}
getRandomNumber(5,10)

  

posted @ 2022-04-08 17:35  萌小心情懂  阅读(36)  评论(0编辑  收藏  举报