How to select choices based on the probability?

For example, if I have three choices. Each choice has its own probability.

choice 1 has probability 0.5 choice 2 has probability 0.2 choice 3 has probability 0.3

How can I implement the selector to choose choices based on their probability?

var rnd : float = Random.value;

if (rnd < 0.5) {
    // ... choice 1
} else if (rnd < 0.7) {
    // .. choice 2
} else {
   // .. choice 3
}