用 lua 写一个 可以控制百分比概率的函数
以下是一个可以控制百分比概率的 Lua 函数:
function probability(percent)
    math.randomseed(os.time())
    local rand = math.random(1, 100)
    if rand <= percent then
        return true
    else
        return false
    end
end
这个函数接受一个参数 percent,表示百分比概率,取值范围为 0-100。函数会生成一个随机数,如果这个随机数小于等于 percent,则函数返回 true,否则返回 false。由于使用了 math.randomseed(os.time()),所以每次调用这个函数时都会产生不同的随机数。
原文地址: https://www.cveoy.top/t/topic/dsPH 著作权归作者所有。请勿转载和采集!