maths.ts 445 Bytes
Newer Older
hucy's avatar
hucy committed
1 2 3 4 5 6 7 8 9 10 11
/**
 * 返回了一个在指定值之间的随机整数
 * @param min 这个值不小于 min (如果 min 不是整数,则不小于 min 的向上取整数)
 * @param max 这个值小于(不等于)max
 * @returns [min ,max )
 */
export const getRandomInt = function (min: number, max: number) {
  min = Math.ceil(min);
  max = Math.floor(max);
  return Math.floor(Math.random() * (max - min)) + min; // 不含最大值,含最小值
};