【发布时间】:2021-01-05 11:03:46
【问题描述】:
我正在创建一个游戏,目前必须处理一些math.randomness。
由于我在 Lua 中没有那么强,你怎么看
- 您能否制定一个算法,使用
math.random并以给定的百分比?
我的意思是这样的函数:
function randomChance( chance )
-- Magic happens here
-- Return either 0 or 1 based on the results of math.random
end
randomChance( 50 ) -- Like a 50-50 chance of "winning", should result in something like math.random( 1, 2 ) == 1 (?)
randomChance(20) -- 20% chance to result in a 1
randomChance(0) -- Result always is 0
但是我不知道如何继续,我完全不擅长算法
我希望你能理解我对我想要完成的事情的错误解释
【问题讨论】:
标签: lua