How do i make rng?

I have created a system to randomly choose a random module but how would i actually get the percentage of them getting that rarity

local RaritiesHandle = {}

RaritiesHandle.Init = function()
	local RandomRarity = script:GetChildren()
	local ChosenIndex = math.random(1, #RandomRarity)
	local ChosenObject = require(RandomRarity[ChosenIndex])
	print(ChosenObject.Chance)
end

return RaritiesHandle

Common Example:

return {
	Rarity = script.Name, 
	Chance = 10, 
	Donut = script["Normal Donut"]
}

I’ve seen a few posts asking the same question. Try searching “choose rarity percentage” (or similar text) with the Search tool up top.

Do you mean choosing, or getting percentage?

local MaxRarityHere = 500 --maximum chance (all added together)

function RaritiesHandle.Choose()
    local num = math.random(1, MaxRarityHere)
    if num < 10 then
        --do stuff
    elseif num >= 10 and num < 30 then
        --do stuff
    end
end

function RaritiesHandle.GetPercentage(rarityItem)
    local percentage = math.floor((rarityItem.Chance / MaxRarityHere) * 100)
    return percentage
end

the search sucks it always shows unrelated things