title: Organize array in certain way (roulette wheel items)
body: <p>I'm struggling with (probably simple) array shuffling/generating algorithm.</p>
  
  <p>I'm creating simple backend (PHP/MySQL) for a roulette wheel game (JS/HTML). The roulette doesn't have numeric values as usual instead there are 4 prizes user can win, distributed within 12 segments of a roulette wheel.</p>
  
  <p>I need an array like this:</p>
  
  <pre><code>// Note that PRIZE4 is listed only once as it is valuable prize.
  // PRIZE3 is less valuable so it is listed twice, etc.
  // Prizes are skipping each other so you should never see two identic prizes next each other.
  var items = [PRIZE1, PRIZE2, PRIZE1, PRIZE2, PRIZE1, PRIZE2, PRIZE1, PRIZE2, PRIZE1, PRIZE3, PRIZE4, PRIZE3];
  </code></pre>
  
  <p>And I have prizes in a SQL table like this:</p>
  
  <pre><code>+----+------------+--------------+
  | id | name       | giveaway_cap |
  +----+------------+--------------+
  |  1 | PRIZE1     |          255 |
  |  2 | PRIZE2     |          300 |
  |  3 | PRIZE3     |           30 |
  |  4 | PRIZE4     |           15 |
  +----+------------+--------------+
  4 rows in set (0.00 sec)
  </code></pre>
  
  <p>Column <code>giveaway_cap</code> determines <em>how many of each prize can be won</em> (I'm storing these counts in different table) but could be used as weight of each prize.</p>
  
  <p>I need some algorithm (preferably PHP) which will generate an array as described above based on this table.</p>
  
  <p>Thanks.</p>