(Python) algorithm to randomly select a key based on proportionality/weight
<p>I'm a bit at a loss as to how to find a clean algorithm for doing the following:</p>

<p>Suppose I have a dict k:</p>

<pre><code>&gt;&gt;&gt; k = {'A': 68, 'B': 62, 'C': 47, 'D': 16, 'E': 81}
</code></pre>

<p>I now want to randomly select one of these keys, based on the 'weight' they have in the total (i.e. sum) amount of keys. </p>

<pre><code>&gt;&gt;&gt; sum(k.values()) 
&gt;&gt;&gt; 274
</code></pre>

<p>So that there's a </p>

<pre><code>&gt;&gt;&gt; 68.0/274.0
&gt;&gt;&gt; 0.24817518248175183
</code></pre>

<p>24.81% percent change that A is selected.</p>

<p>How would you write an algorithm that takes care of this? In other words, that makes sure that on 10.000 random picks, A will be selected 2.481 times?</p>
