Files
Leviathan/GameServer/AziaMafiaScriptsBackup/Funzone/require/better random.lua
T
2026-06-01 12:46:52 +02:00

51 lines
858 B
Lua

function random_chance(tab_percent) -- returns true a given percentage of calls
temp = 0
maxi = 0
for k = 1 , table.getn(tab_percent) do
maxi = maxi + tab_percent[k]
end
per_pick = math.random(1,maxi)
for i= 1 , table.getn(tab_percent) do
---debut de tableau
if i == 1 and (per_pick >= 1 and per_pick <= tab_percent[i] ) then
return i , per_pick
else
---- reste tableau
if per_pick >= temp+1 and per_pick <= tab_percent[i]+temp then
return i , per_pick
end
end
temp = temp + tab_percent[i]
end
end
function random_chance_tab(tab)
local b = random(1, table.getn(tab) )
b = tab[b]
return b
end
function try2() -- /run try2()
tab_percent = {10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10}
pick , per_pick = random_chance(tab_percent)
cprint("per_pick " .. per_pick)
cprint("pick " .. pick)
cprint("---")
end