Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: RE (tilly) 2: Randomize an array

by blazar (Canon)
on Aug 01, 2008 at 20:51 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://701772]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (4)
As of 2024-04-19 03:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found