I have a system where I can have multiple choices with multiple possible percentages/probabilities. Eg
A - 20% B - 30% C - 50%
I want to choose one of them based on the probability. I can think of how to do it where I build ranges for each such as
A = 0-20 B = 20-50 C = 50-100
But it seems messy that I have to build a range for B based on the values that came before in generating the other parts of the range.
I'm wondering if there is a more elegant way to do this?
*I'm programming this in PHP - extra points for code!