title: How can I make a random choice according to probabilities stored in a list (weighted random distribution)?
body: <p>Given a list of probabilities like:</p>
  <pre><code>P = [0.10, 0.25, 0.60, 0.05]
  </code></pre>
  <p>(I can ensure that the sum of all the variables in P is always 1)</p>
  <p>How can I write a function that randomly returns a valid index, according to the values in the list? In other words, for this specific input, I want it to return <code>0</code> 10% of the time, <code>1</code> 25% of the time, <code>2</code> 60% of the time and <code>3</code> the remainind 5% of the time.</p>