Original Post
I need to implement a function where it selects randomly from a pool of candidates, but has a higher probability of choosing some over others (bias).
Now, of course, I''ll use the rand() function, but how do I add a percentage-based probability of choosing.
Say I have 5 items, with the following probability:
1 - 25%
2 - 5%
3 - 30%
4 - 20%
5 - 20%
I was thinking having the rand function choose a number between 0 and 100. Now, if the number is from 0 to 25, it will choose 1, if it is from 25 to 30, it will choose 2, if it is from 30 to 60, it will chose 3, and so forth.
Is this a good approach, or is there a better one?