I want a function to return the values 0, 1 or 2 based on a random chance. Let's say 10% 0, 30% 1, 60% 2. How can this be achieved?
What I would normally do is this:
on "function"
random(100) < 10 -> return 0
random(100) < 30 -> return 1
random(100) < 60 -> return 2
But in doing this, the first one in the list will get a significantly smaller chance of happening, as the last ones will replace the final value
Ex:
Ok, the 10% went through, and the return value is set to 0. But wait, the 60% chance also went through, so the return value is now 2. So this will cause the 10% to be much less than actually 10%
I tried using "else", but this has the opposite effect:
on "function"
random(100) < 10 -> return 0
else random(100) < 30 -> return 1
else random(100) < 60 -> return 2
So, the second chance will only fire assuming the first one failed, so that causes the second one to only even fire 90% of the time
EDIT: I think I've found a way... I'll test it and post here later