Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

RE: Randomize an array

by KM (Priest)
on Sep 08, 2000 at 00:13 UTC ( #31474=note: print w/replies, xml ) Need Help??

Help for this page

Select Code to Download


  1. or download this
        my @array = qw /one two three four five six/;
        for (my $i = @array; -- $i;) {
            my $r = int rand (1 + $i);
            @array [$i, $r] = @array [$r, $i] unless $r == $i;
        }
    
  2. or download this
    use Algorithm::Numerical::Shuffle qw/shuffle/;
    my @array = shuffle qw/one two three four five/;
    

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (2)
As of 2019-05-26 08:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Do you enjoy 3D movies?



    Results (153 votes). Check out past polls.

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