I was messing around with math.random() in some practice places when I decided to code out a sort of draw system you find in a lot of mobile games. You know - open a super mystery box and have a 70% chance for a common item, 20% for uncommon, 10% for a rare, etc.
I took the obvious route with if statements like this
-- Note: ignore any typos I forgot I'm on a different computer :P
math.randomseed(tick())
randomNumber = math.random(0,100)
if randomNumber >= 0 and randomNumber < 70 then
-- 70% chance code
elseif randomNumber >= 70 and randomNumber < 90 then
-- 20% chance code
elseif randomNumber >= 90 then
-- 10% chance code
end
So I'm curious how you would improve this as if you wanted to chance the probability of one category you'd likely have to change most of the other ones as well. I really feel like I'm missing something incredibly obvious that I could be using.
Thanks a bunch!

1 comment
This is called 'Fitness Proportionate Selection' in the computing world: https://en.wikipedia.org/wiki/Fitness_proportionate_selection