Just for fun, here a poor mans shuffle:
DB<228> sort { (-1)**(rand(2)%2) } 1..10
=> (5, 8, 7, 6, 9, 10, 1, 4, 2, 3)
Surely neither efficient, nor well mixed and pretty pointless since List::Util is core. =)
Cheers Rolf
( addicted to the Perl Programming Language)
update
for completeness:
> nor well mixed
The distribution is perfect iff the list has 2^n elements
DB<483> for (1..100000) {$x=0;$g[$x++]{$_}++ for sort {(-1) ** int r
+and 2} a..d }
=> ""
DB<484> \@g
=> [
{ a => 25302, b => 25028, c => 24852, d => 24818 },
{ a => 25062, b => 24925, c => 24773, d => 25240 },
{ a => 24773, b => 24944, c => 25203, d => 25080 },
{ a => 24863, b => 25103, c => 25172, d => 24862 },
]
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.