in reply to Re: Is this a fair shuffle?
in thread Is this a fair shuffle?
Along the lines you mentioned, this works:
my @shuffled = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [ $_, rand() ] } @unshuffled;
But compared to other approaches it is slow and memory-expensive.
This topic came up at a recent kw.pm meeting, and I played around and did some rudimentary benchmarks:
http://kw.pm.org/wiki/index.cgi?ListShuffle2005-04-02 Janitored by Arunbear - replaced pre tags with code tags, to allow code extraction
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Is this a fair shuffle?
by Thargor (Scribe) on Apr 01, 2005 at 19:55 UTC | |
by fishbot_v2 (Chaplain) on Apr 01, 2005 at 21:59 UTC | |
|
Re^3: Is this a fair shuffle?
by Anonymous Monk on Apr 01, 2005 at 19:45 UTC |