Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
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 taking refuge in the Monastery: (5)
As of 2024-03-29 21:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found