Say I have a table like:
skins = {desert_camouflage = 10, forest_camouflage = 20}
Where "desert_camouflage" is weighted rarer than "forest_camouflage".
I am searching for a Rbx.Lua RNG function that will print it's result.
Try my solution:
function weighted_random (weights)
local summ = 0
for i, weight in pairs (weights) do
summ = summ + weight
end
if summ == 0 then return end
-- local value = math.random (summ) -- for integer weights only
local value = summ*math.random ()
summ = 0
for i, weight in pairs (weights) do
summ = summ + weight
if value <= summ then
return i, weight
end
end
end
I don't think so, but it's easy to write yourself: