For a while now I have been looking into making an egg hatching system like Bubble Gum Simulator but I am not sure how they do their chances below 1. For example, lets say the most common pet is 35% chance but rarest is 0.001% chance. How would I go about that?
I have tried solutions such as a random number 1,100k and the 0.001 is equal to 1 and make it so if the random number is equal to 1 itll pick that pet but i dont know if its effective and works well because i have had some parts where a pet could be one in one thousand and you could open ten thousand but none hatched
My code:
math.randomseed(tick())
local petModule = {}
petModule.pets = {
["Secret3"] = {
"Neon Unicore"
};
["Secret2"] = {
"Ultimate Frog"
};
["Secret1"] = {
"Party Bell"
};
["Legendary3"] = {
"Sweet Dragon"
};
["Legendary2"] = {
"Chocolate Cake"
};
["Legendary1"] = {
"Piñata"
};
["Epic1"] = {
"Party Bear"
};
["Rare1"] = {
"Neon Bunny"
};
["Uncommon1"] = {
"Party Cat"
};
["Common1"] = {
"Neon Doggy"
};
}
petModule.rarities = {
["Secret3"] = 1;
["Secret2"] = 3;
["Secret1"] = 10;
["Legendary3"] = 100;
["Legendary2"] = 500;
["Legendary1"] = 2500;
["Epic1"] = 50000;
["Rare1"] = 300000;
["Uncommon1"] = 1646886;
["Common1"] = 3000000;
}
petModule.choosePet = function(player)
local luck = 1
local randomNumber = math.random(1, 5000000)
if randomNumber <= 1 * luck then
local rarity = "Secret"
local rarityTab = petModule.pets["Secret3"]
local chosenPet = rarityTab[1]
return chosenPet, rarity
elseif randomNumber <= 3 * luck then
local rarity = "Secret"
local rarityTab = petModule.pets["Secret2"]
local chosenPet = rarityTab[1]
return chosenPet, rarity
elseif randomNumber <= 10 * luck then
local rarity = "Secret"
local rarityTab = petModule.pets["Secret1"]
local chosenPet = rarityTab[1]
return chosenPet, rarity
elseif randomNumber <= 100 * luck then
local rarity = "Legendary"
local rarityTab = petModule.pets["Legendary3"]
local chosenPet = rarityTab[1]
return chosenPet, rarity
elseif randomNumber <= 500 * luck then
local rarity = "Legendary"
local rarityTab = petModule.pets["Legendary2"]
local chosenPet = rarityTab[1]
return chosenPet, rarity
elseif randomNumber <= 2500 * luck then
local rarity = "Legendary"
local rarityTab = petModule.pets["Legendary1"]
local chosenPet = rarityTab[1]
return chosenPet, rarity
elseif randomNumber <= 50000 * luck then
local rarity = "Epic"
local rarityTab = petModule.pets["Epic1"]
local chosenPet = rarityTab[1]
return chosenPet, rarity
elseif randomNumber <= 300000 * luck then
local rarity = "Rare"
local rarityTab = petModule.pets["Rare1"]
local chosenPet = rarityTab[1]
return chosenPet, rarity
elseif randomNumber <= 1646886 * luck then
local rarity = "Uncommon"
local rarityTab = petModule.pets["Uncommon1"]
local chosenPet = rarityTab[1]
return chosenPet, rarity
elseif randomNumber > 1646886 * luck then
local rarity = "Common"
local rarityTab = petModule.pets["Common1"]
local chosenPet = rarityTab[1]
return chosenPet, rarity
end
end
return petModule