title: Python: Select Item from Object List Based on Probability
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/352670/weighted-random-selection-with-and-without-replacement">Weighted random selection with and without replacement</a>  </p>
  </blockquote>
  
  
  
  <p>I have a long object list of items. I want to randomly select an item from the list based on the probability. The list looks like the following:</p>
  
  <pre><code>class Item:
    def __init__(self, pid, hits, qtyPerOrder):
      self.pid = pid
      self.bay = hits
      self.qtyPerOrder = int(qtyPerOrder)
  
  itemList = [('RGSCAF', 181  ,6), ('WAR10227', 54    ,3), ('AD2020WOC', 31   ,4)]
  </code></pre>
  
  <p>Basically, I want a function that will go through the list, assign probability weights based on hits, then randomly choose n number of objects based on the probability. So in this example, there would be a higher probability that the object ('RGSCAF', 181 ,6) is returned since it has the highest hits value.</p>