Help fixing my random pet system

Okay so, I’m currently making an egg hatching system and I’m stuck on the part when I need to get a random pet, this pet system is working on percentages
here is the rarity table for the first egg

		Rarities = {
			{"Dog", 50};
			{"Cat", 30};
			{"Bunny", 20};
			{"Mouse", 0.1};
		}

I think i’ve done something wrong, I’m not sure if this system is the best, how can I improve it?

local function GetRealLength(LowestPercentage)
	local TempLow = LowestPercentage
	local MultiTimes = 0
	while TempLow < 0.1 do
		MultiTimes += 1
		TempLow *= 10			
	end
	MultiTimes += 1
	local RealLength = (tostring(TempLow):len() - 2) * (MultiTimes)
	LowestPercentage = string.format("%."..tostring(RealLength).."f",LowestPercentage)
	return (RealLength > 0 and RealLength or 1) , 100 * (10^RealLength), LowestPercentage
end

local function GetRandomPet(EggName)
	local Rarities = GetRarities(EggName)
	
	table.sort(Rarities, function(a, b)
		return a[2] < b[2]
	end)
	local LowestPercentage = Rarities[1][2] 
	
	local MaxNumber = 100
	local RealLength = 1
	if LowestPercentage < 1 then
		RealLength, MaxNumber = GetRealLength(LowestPercentage)
	end
	local RandomNumber = RNG:NextInteger(1,MaxNumber)
	RandomNumber /= (10^RealLength)
	print(RandomNumber)
	for i,v in ipairs(Rarities) do		
		if RandomNumber <= v[2] then
			print(v[1])
			break
		end
		RandomNumber -= v[2]
	end
end

If you find any problem/Things I can do to improve, please tell me.
Thanks

Use math.random for random numbers also remove the numbers in the Rarities Table It Wont Do It Instead Do

		Rarities = {
		"Dog";
		"Dog";
		"Dog";
		"Dog";
		"Dog";
		"Cat";
		"Cat";
		"Cat";
		"Bunny";
		"Bunny";
		"Mouse";
		}

local Pet = Rarities[math.random(1,#Rarities)]

uhh thats not the right way, if i will want pets having a chance of 0.001 or something like that

well i am sure you can label them like this:

		Rarities = {
		[50] = "Dog";
		[30] ="Cat";
		[20] = "Bunny";
		[0.1] = "Mouse";
		}

it will still be the same as my code, im just doing v[2] instead of index

I’ve made a new random system

function RandomPetModule:GetRandomPet(EggName)
	local Rarities = self:GetRarities(EggName)

	table.sort(Rarities, function(a, b)
		return a[2] < b[2]
	end)

	local Sum = 0
	for i,v in ipairs(Rarities) do
		Sum += v[2]
	end

	local RandomNumber = Sum*RNG:NextNumber()
	local currentIndex = 0
	for _,item in ipairs(Rarities) do
		local pet,Chance = item[1],item[2]
		currentIndex += Chance
		if RandomNumber<currentIndex then
			return pet
		end
	end
end