Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: Shuffle an array

by DamnDirtyApe (Curate)
on Nov 09, 2002 at 20:26 UTC ( [id://211676]=note: print w/replies, xml ) Need Help??


in reply to Shuffle an array

I'm suprised no one has mentioned it yet, but List::Util has a shuffle() method that does just that.

use List::Util qw( shuffle ) ; my @arr = qw( a b c d e f A B C D E F ) ; print( ( map { "[$_]" } @arr ), "\n" ) ; for ( 1..5 ) { print( ( map { "[$_]" } shuffle @arr ), "\n" ) ; }

_______________
DamnDirtyApe
Those who know that they are profound strive for clarity. Those who
would like to seem profound to the crowd strive for obscurity.
            --Friedrich Nietzsche

Log In?
Username:
Password:

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

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

    No recent polls found