Hmm ... the complexity of this question depends on your definition of "random".

How random is random enough???

You can always quickly construct a solution - iff possible - but it's kind of predictable (symmetrical) then.

Sort your groups by length and organize them in columns of length of the biggest group than read the matrix from left to right.

Demo:

qw( a a a a b b b c c )

==>

a b c a b a b a c

==>

qw( a b c a b a b a c )

update

and I think based on this you could create more solutions by randomly shuffling complete rows and columns of the matrix and reading from left to right again

1 2 0 3 c a 2 b a 0 b c a 1 b a

==>

qw( c a b a b c a b a )

Hence plenty of legal solutions° (not all unique) to pick from.

Super fast and easy. But is this "random" enough???

Cheers Rolf
(addicted to the Perl Programming Language :)
see Wikisyntax for the Monastery

°) 3!*4!/2 = 72 unique solutions in this case


In reply to Re: Algorithm RFC: fast (pseudo-)random shuffle with no repetition by LanX
in thread Algorithm RFC: fast (pseudo-)random shuffle with no repetition by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.