Sol's rng type rolling system

Hello, there is a game called sol’s rng: (5) Sol’s RNG - Roblox

in that game you can roll and it will give you a random item, items have probability like 1 in 2, 1 in 100 etc
now how can i achieve something like that? all i need is a function which will return a random item from a table [the higher probability = the harder to get]

I have my table here

local SwordModule = {
	{model = nil, probability = 2},
	{model = nil, probability = 2},
}
1 Like
local function getRandomItem(t)
    local totalProbability = 0
    for _, item in ipairs(t) do
        totalProbability += item.probability
    end
    
    local randomNumber = math.random(1, totalProbability)
    
    local cumulativeProbability = 0
    for _, item in ipairs(t) do
        cumulativeProbability += item.probability
        if randomNumber <= cumulativeProbability then
            return item.model
        end
    end
end

print(getRandomItem(SwordModule)) --example: prints the item

Here’s the function

If you wanna make a rolling system similar to sols rng, you’re gonna need to use percentages, also called weights. Im also pretty sure there are tutorials on youtube that go into depth on how to create a similar system.

Is this the function that sol’s rng uses?

I don’t work for Sol’s RNG , so… I don’t know :person_shrugging: .

Try watching this playlist:

1 Like