Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

RE: Randomize an array

by KM (Priest)
on Sep 08, 2000 at 00:13 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://31474]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-19 20:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found