title: Random number with Probabilities
body: <p>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?</p>
  
  <p>e.g.</p>
  
  <p>Generate random integers from within [1;3] with the following probabilities:</p>
  
  <p>P(1) = 0.2<br>
  P(2) = 0.3<br>
  P(3) = 0.5<br></p>
  
  <hr>
  
  <p>Right now I am considering the approach to generate a random integer within [0;100] and do the following:</p>
  
  <p>If it is within [0;20] --> I got my random number 1.<br>
  If it is within [21;50] --> I got my random number 2.<br>
  If it is within [51;100] --> I got my random number 3.<br>
  <br>
  What would you say?</p>