in reply to Re^4: Is this a fair shuffle?
in thread Is this a fair shuffle?
That's close, but try it on a list with repetitions:sub qshuf { my %hash; sort { ($hash{$a}||=rand 1) <=> ($hash{$b}||=rand 1) } @_; }
All the D's in the list get the same random value, so they all tie each other in the comparisons and end up adjacent. You are better off using the Schwartzian Transform I outlined above, where each array position gets a unique random number.for (1 .. 10) { print qshuf(qw/a b c D D D D/), $/; }
blokhead
|
|---|