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;
}

這兩個函數的區別是啥?

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

 function getRandomInt(min, max) {
  return Math.floor(Math.random() * (max - min)) + min; 能获得的值范围是min<=x<max
}
 function getRandomIntInclusive(min, max) {
  return Math.floor(Math.random() * (max - min + 1)) + min;  能获得的值范围是min<x<=max
}