Most accurate rarity algorithm

what would be the most accurate rarity logic for example for pet system?

here is what i made for it

function EggService:SelectRandomPet(eggname: string)
    local totalchance = 0
    local tempchance = 0

    for _, chance in pairs(EggModule.GetAllPets(eggname)) do
        totalchance += chance

    local RandomNum = math.random() * totalchance

    for petname, chance in pairs(EggModule.GetAllPets(eggname)) do
        tempchance += chance
        if RandomNum <= tempchance then
            return petname

do you think its accurate ?

1 Like

Floats have about 7 digits of precision, so as long as all your chancse are much more than 1 / 10^7, it is proportionally accurate.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.