in reply to Re: Re: Re: Fisher-Yates shuffle?
in thread Fisher-Yates shuffle?

Just to show I do listen:).

As you don't object to $a and do object to slices and the reliance on subscript evaluation order, I offer this: (it passes Abigail-II's test!!)

$_ ne ($a=int( rand( $#values-$_+1))+$_) and $values[$_] ^= $values[$a] ^= $values[$_] ^= $values[$a] for (0..$#values); # Fisher-Yates one-liner

Its a shame you can't use an named iterator with the for (list) statement modifier otherwise I would have this as:

$b ne ($a=int(rand($#values-$b+1))+$b) and $values[$b] ^= $values[$a] ^= $values[$b] ^= $values[$b] for $b (0..$#values);

Then noone could complain about the use of $a and $b...they are used for swapping aren't they?

UpdateI forgot to mention...I had to re-institute the don't swap if same test for this to work, but given some C-compilers used the 3-Xor's trick to optomise register swaps in register constrained situations, I wonder if this was the real reason for that test in the oeriginal Fisher-Yates C code?