SOURCE

function randomFun (rank, chanceNum) {
    let res = false
    let randomNum = Math.floor(Math.random()*rank)
    let randomArr = randomArrHandle(rank,rank,0).slice(0, chanceNum)
    console.log(22,randomNum,randomArr)
    return randomArr.includes(randomNum)

}
// 计算指定长度、范围的随机数组
function randomArrHandle(len, max, min){
    let arr = []
    while (arr.length < len) {
        let temp = Math.floor(Math.random()*(max-min)) + min
        if (!arr.includes(temp)) {
            arr.push(temp)
        }
    }
    return arr
}
// 测试
let rank = 100
let chance = 10
function testFn() {
    for (let i=0;i<chance;i++){
        console.log(i,randomFun(rank,chance))
    }
}
testFn()
console 命令行工具 X clear

                    
>
console