in reply to Re^3: Is this a fair shuffle?
in thread Is this a fair shuffle?
That is, it caches the value for each pairwise comparison, but it still doesn't shuffle well. Of course, there is the possibility of a > b > c > a...sub qshuf { my %hash; sort { $hash{$a}{$b}||=(.5 <=> rand 1) } @_; }
Update: I have a winner!
sub qshuf { my %hash; sort { ($hash{$a}||=rand 1) <=> ($hash{$b}||=rand 1) } @_; } Rate xform slice shufl qshuf xform 65.6/s -- -34% -72% -100% slice 99.7/s 52% -- -57% -100% shufl 233/s 255% 133% -- -99% qshuf 44494/s 67764% 44534% 19019% -- permutation | slice | xform | shufl | qshuf -------------------------------------------------- Std. Dev. | 69.974 | 58.895 | 53.532 | 62.689
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Is this a fair shuffle?
by blokhead (Monsignor) on Apr 01, 2005 at 05:29 UTC | |
|
Re^5: Is this a fair shuffle?
by BrowserUk (Patriarch) on Apr 01, 2005 at 05:18 UTC | |
by Roy Johnson (Monsignor) on Apr 01, 2005 at 11:51 UTC | |
by BrowserUk (Patriarch) on Apr 01, 2005 at 12:00 UTC | |
by Roy Johnson (Monsignor) on Apr 01, 2005 at 12:08 UTC | |
|
Re^5: Is this a fair shuffle?
by Anonymous Monk on Apr 01, 2005 at 09:39 UTC |