zzzcsd 2016-03-27 01:13 采纳率: 0%
浏览 1244

Javascript中獲取某個範圍的正整數?

 function getRandomInt(min, max) {
  return Math.floor(Math.random() * (max - min)) + min;
}
 function getRandomIntInclusive(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;
}

這兩個函數的區別是啥?

  • 写回答

2条回答 默认 最新

  • Crabime 2016-03-27 01:35
    关注

    因为random函数是不能得到零这个数的

    评论

报告相同问题?