小编jar*_*rgl的帖子

Lua:随机:百分比

我正在创造一个游戏,目前必须处理一些问题math.random.

因为我在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
Run Code Online (Sandbox Code Playgroud)

但是我不知道如何继续,我完全厌恶算法

我希望你能理解我对我要完成的事情的错误解释

lua

3
推荐指数
2
解决办法
4518
查看次数

标签 统计

lua ×1