in reply to My Perl Obfuscator

sub Shuffle { for (my $i = 0; $i < @_; $i++) { my $R = int(rand(@_)); @_[$R, $i] = @_[$i, $R]; } return 0; }

See perldoc -q shuffle for a better shuffle algorithm

Naked blocks are fun! -- Randal L. Schwartz, Perl hacker

Replies are listed 'Best First'.
Re^2: My Perl Obfuscator
by ikegami (Patriarch) on Jan 12, 2024 at 23:20 UTC

    It's almost the same algorithm. The only difference is that the OP's always picks an item from the complete set, whereas Fisher-Yates picks from the set of unassigned items. I don't know if that affects the fairness of the algorithm. It's easy to see that F-Y is fair, but it's hard to see if the OP's is or not. [Upd: After some experimentation, I believe the OP's algorithm isn't fair, and is thus buggy.]