title: Best way of setting up probabilities for multiple items in Java?
body: <p>I'm really used to writing if statements for two different events, which could be best outlined by the following pseudocode:</p>
  
  <pre><code>double random = Math.random();
  if(random&lt;0.5) event A;
  else event B;
  </code></pre>
  
  <p>But when there's more than 2 different events (let's say 4 in this instance) with different probabilities, the only thing I've found is the following, but it seems way too verbose for the simple thing I'm trying to achieve, there has to be a much simpler way to do this, right? </p>
  
  <pre><code>double random = Math.random();
  if(random&lt;0.3) event A;
  else if(random&gt;=0.3 &amp;&amp; random&lt;0.5) event B;
  else if (random&gt;=0.5 &amp;&amp; random&lt;0.8) event C;
  else event D;
  </code></pre>
  
  <p>Clearly there's a better algorithm to do this? </p>