function random(min, max) {
min = Math.ceil(min) // 向上取整
max = Math.floor(max) // 向下取整
// 为了包括最大值要在之后加上1 可以取到闭区间[min,max]
let result = Math.floor(Math.random() * (max - min + 1)) + min
return result
}
random(-10, 10)
function random(min, max) {
min = Math.ceil(min) // 向上取整
max = Math.floor(max) // 向下取整
// 为了包括最大值要在之后加上1 可以取到闭区间[min,max]
let result = Math.floor(Math.random() * (max - min + 1)) + min
return result
}
random(-10, 10)