title: Distributed probability random number generator
body: <p>I want to generate a number based on a distributed probability. For example, just say there are the following occurences of each numbers:</p>
  
  <pre><code>Number| Count           
  1    |  150                
  2    |  40          
  3    |  15          
  4    |  3  
  
  with a total of (150+40+15+3) = 208     
  then the probability of a 1 is 150/208= 0.72    
  and the probability of a 2 is 40/208 = 0.192    
  </code></pre>
  
  <p>How do I make a random number generator that returns be numbers based on this probability distribution?</p>
  
  <p>I'm happy for this to be based on a static, hardcoded set for now but I eventually want it to derive the probability distribution from a database query.</p>
  
  <p>I've seen similar examples like <a href="https://stackoverflow.com/questions/3016439/probability-random-number-generator">this one</a>  but they are not very generic. Any suggestions?</p>