A loaded die doesn’t land on every outcome equally often: chances[i] is how often outcome i comes up, and the chances add up to 1. A computer can only roll fair: random.random() gives a roll, a number from 0 up to (not including) 1, every value equally likely. Write pick(chances, roll): the outcome (its index, from 0) that this roll gives, so that over many rolls each outcome comes up as often as its chance. The same roll always gives the same outcome.
| outcome 0 | outcome 1 | outcome 2 |
|---|---|---|
| 0.5 | 0.3 | 0.2 |