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 },
]
|