I have these four variables:
local RarityBasic = 0.4 -- The probability. local RarityRare = 0.3 local RarityLegendary = 0.2 local RarityExotic = 0.1
Where the number is the probability. I want a way of randomly choosing one of them taking into account the probability that each thing has.
The output would be something like:
print("Rarity: "..Rarity) >> Rarity: Basic
How would I do this?
Do something like this :
math.randomseed(tick()) local number = math.random(1,10) if number == 1 then print("Rarity : Exotic") elseif number >= 2 and number <=3 then print("Rarity : Legendary") elseif number >= 4 and number <=6 then print("Rarity : Rare") elseif number >= 7 and number <= 10 then print("Rarity : Basic") end
It basically assigns different chances to each rarity so the exotic has a 10% chance, legendary has 20% chance, etc.