Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: random elements from array - new twist

by Gilimanjaro (Hermit)
on Nov 06, 2002 at 10:09 UTC ( [id://210700]=note: print w/replies, xml ) Need Help??


in reply to random elements from array - new twist

Here's my solution... Might not be the cleanest (passing the whole array) but it sure looks pretty...
($\,$,)=("\n","\t"); @a=(1..15); print "Before:",@a; print "Selection:",picksome(5,@a); print "After:",@a; sub picksome { map { splice @_, rand @_, 1 } (1..shift) }

Log In?
Username:
Password:

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

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

    No recent polls found