js 随机数

2019-06-20  本文已影响0人  Sasoli

得到一个两数之间的随机整数,包括两个数在内

function getRandomIntInclusive(min, max) {
  min = Math.ceil(min);
  max = Math.floor(max);
  return Math.floor(Math.random() * (max - min + 1)) + min; //含最大值,含最小值 
}

得到一个两数之间的随机整数

function getRandomInt(min, max) {
  min = Math.ceil(min);
  max = Math.floor(max);
  return Math.floor(Math.random() * (max - min)) + min; //不含最大值,含最小值
}
上一篇 下一篇

猜你喜欢

热点阅读