weighted choice / selection with probability
in
Programming Questions
•
2 years ago
hi,
i want to choose one random value out of 4, but for every of these 4, there should be a certain probability of how probable that one is picked. the only solution i came up with so far is, if i have for example probabilities like 2, 3, 3 and 2 for the values A, B, C, and D, to generate a random int i between 1 and 10 and then have an if-else-if-construction that selects value A if (1 <= i <= 2) , B if (3<= i <=5), C id (6<= i <=8) and D if (9 <= i <=10).
is there another solution for that?
thx florian.
1