Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: RE (tilly) 2: Randomize an array

by blazar (Canon)
on Aug 01, 2008 at 20:51 UTC ( #701772=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
    my @shuffled = sort {.5<rand} @input;
    
  2. or download this
    my %r;
    my @shuffled = sort { ($r{$a}||=rand) <=> ($r{$b}||=rand) } @input;
    
  3. or download this
    my @r = map rand, @input;
    my @shuffled = @input[sort {$r[$a] <=> $r[$b]} 0..$#input];
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (9)
As of 2019-05-21 16:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you enjoy 3D movies?



    Results (136 votes). Check out past polls.

    Notices?
    • (Sep 10, 2018 at 22:53 UTC) Welcome new users!