I want to pseudo-randomly pick one element from an array of 5 elements: I want to control the occurrence probability of each of those 5 elements.
Example: I have an array like this: [A B C D E]
- I want the probability to pick A: 0.10 (10%)
- I want the probability to pick B: 0.10 (10%)
- I want the probability to pick C: 0.20 (20%)
- I want the probability to pick D: 0.20 (20%)
- I want the probability to pick E: 0.40 (40%)
I have seen that I can weight a random selection from an array here: Weighted random selection from array.
How can I weight elements contained in an array like this?