title: Algorithm to shuffle an Array randomly based on different weights
body: <p>I have a collection of elements that I want to shuffle randomly, but every element has a different priority or weight. So the element with bigger weight has to have more probabilities to be on the top of the result.</p>
  <p>I have this Array:</p>
  <pre><code>elements = [
    { :id =&gt; &quot;ID_1&quot;, :weight =&gt; 1 },
    { :id =&gt; &quot;ID_2&quot;, :weight =&gt; 2 },
    { :id =&gt; &quot;ID_3&quot;, :weight =&gt; 6 }
  ]
  </code></pre>
  <p>And I want to shuffle it so the element with id <code>&quot;ID_3&quot;</code> has <em>~6 times</em> more probabilities to be first than the element <code>&quot;ID_1&quot;</code> and <em>~3 times</em> more probabilities than the element <code>&quot;ID_2&quot;</code>.</p>
  <h3> Update</h3>
  <p>Clarification: once you have chosen the first position the other elements will <em>fight</em> for the rest positions using the same logic.</p>