How to make a weighted RNG in ROBLOX Lua? (Like CS:GO cases) -



How to make a weighted RNG in ROBLOX Lua? (Like CS:GO cases) -

say have table like:

skins = {desert_camouflage = 10, forest_camouflage = 20}

where "desert_camouflage" weighted rarer "forest_camouflage".

i searching rbx.lua rng function print it's result.

i don't think so, it's easy write yourself:

function(weights) local sum = 0 _, v in next, weights if v < 0 or math.floor(v) ~= v error "weights must non-negative integers" end sum = sum + v end sum = math.random(sum) k, v in next, weights sum = sum - v if sum <= 0 homecoming k end end error "should not happen." end

lua roblox

Comments

Popular posts from this blog

javascript - THREE.js reposition vertices for RingGeometry -

javascript - I need to update the text of a paragraph by inline edit -

assembly - What is the addressing mode for ld, add, and rjmp instructions? -