Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
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 drinking their drinks and smoking their pipes about the Monastery: (14)
As of 2019-10-22 13:54 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?