Given a dictionary of weights that sum to 1 - how to use random to select a weighted key
<p>I have a dictionary that looks like this.</p>

<pre><code>mychoice = {0.7: 2, 0.2: 1, 0.1:3}
</code></pre>

<p>I will use the following to select which value to use.  In the above, value 2 will be selected 70% of the time and value 1 will be selected 20% of the time and 3, 10% of the time.</p>

<p>What is the best method to use the following to generate a random number between  0 and 1 and to select randomly the value to use? </p>

<pre><code>from random import random
ran = random()
if ran&gt;.10 and &lt;.30 then select value 1 with a key of .20
</code></pre>

<p>Thanks</p>
