How to display the items from a dictionary in a random order but no two adjacent items being the same
<p>First of all, there is actually more restrictions than stated in the title. Plz readon.</p>

<p>say, i have a <code>dictionary&lt;char,int&gt;</code> where key acts as the item, and value means the number of occurrence in the output. (somewhat like weighting but without replacement)
e.g. ('a',2) ('b',3) ('c',1)</p>

<p>a possible output would be  'babcab'</p>

<p>I am thinking of the following way to implement it.</p>

<ol>
<li>build a new list containing (accumulated weightings,char) as its entry.</li>
<li>randomly select an item from the list, </li>
<li>recalculate the accumulated weightings, also set the recent drawn item weighing as 0.</li>
<li>repeat.</li>
</ol>

<p>to some extent there might be a situation like such: 'bacab' is generated, but can do no further (as only 'b' left, but the weighting is set to 0 as no immediate repetition allowed). in this case i discard all the results and start over from the very beginning.</p>

<p>Is there any other good approach?</p>

<p>Also, what if i skip the "set the corresponding weighting to 0" process, instead I reject any infeasible solution. e.g.  already i got 'bab'. In the next rng selection i get 'b', then i redo the draw process, until i get something that is not 'b', and then continue.  Does this perform better?</p>
