Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: My Perl Obfuscator

by jwkrahn (Abbot)
on Jan 11, 2024 at 21:11 UTC ( [id://11156892]=note: print w/replies, xml ) Need Help??


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.]

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11156892]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-05-18 16:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found