在场景种是否有遇到过概率比来的到值呢
这里提供一个Lua的代码做思路。
function test(table1, table2)
if table1== nil or table2== nil then
return
end
local price = 0
local pricetable ={}
for _,v in ipairs(table2) do
price = v + price
table.insert(pricetable,price)
end
local m_random = math.random(1,price)
for i,v in ipairs(pricetable) do
if m_random <= v then
return table1[i]
end
end
end