Random number with Probabilities
I am wondering what would be the best way (e.g. in Java) to generate random numbers within a particular range where each number has a certain probability to occur or not? e.g. Generate random integers from within [1;3] with the following probabilities: P(1) = 0.2 P(2) = 0.3 P(3) = 0.5 Right now I am considering the approach to generate a random integer within [0;100] and do the following: If it is within [0;20] --> I got my random number 1. If it is within [21;50] --> I got my random number 2. If it is within [51;100] --> I got my random number 3. What would you say? Yours is a pretty good way