petModule.rarities={Legendary=5;Rare=15,Uncommon=30;Common=50}petModule.chooseRandomPet=function()local o=math.random(1,100)local G=0 for m,O in pairs(petModule.rarities)do G=G+O if o<=G then local o=petModule.pets[m]local G=o[math.random(1,#o)]return G end end end return petModule
-- Weighted selection
-- 100 total weight
petModule.rarities = {

	["Legendary"] = 5, -- 5% chance

	["Rare"] = 15, -- 15% chance

	["Uncommon"] = 30, -- 30% chance

	["Common"] = 50, -- 50% chance
}

petModule.chooseRandomPet = function()
	local randomNumber = math.random(1, 100)

	local counter = 0

	for rarity, weight in pairs(petModule.rarities) do
		counter = counter + weight
		if randomNumber <= counter then
			local rarityTable = petModule.pets[rarity]
			local chosenPet = rarityTable[math.random(1, #rarityTable)]

			return chosenPet
		end
	end
end

return petModule
