Wait, nobody's going to suggest the generic solution?
- Concatenate inputs into a list of numbers
- Calculate sum of all values
- Obtain random value (rand * sum)
- Find greatest i where sum(list[0..i]) < value
- Return i (your index)
That would work for more than 3! And in some ways, may better represent what's happening. Not saying it's *faster* at all.