Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re^3: removing the goto

by imp (Priest)
on Jun 01, 2007 at 18:43 UTC ( #618817=note: print w/replies, xml ) Need Help??


in reply to Re^2: removing the goto
in thread removing the goto

It might be more appropriate to do the shuffle before the uniq if the OP wants the duplicate values to have a greater chance of being selected - as suggested by the name @weighteddiv.
use List::Util 'shuffle'; use List::MoreUtils 'uniq'; use strict; my @weighteddiv = ( (1..50), (1..10) x 10, ); my @shuffle1 = shuffle( uniq @weighteddiv ); my @shuffle2 = uniq( shuffle @weighteddiv ); printf "shuffle1: %s\n", join(', ', sort {$a <=> $b} @shuffle1[0..10]) +; printf "shuffle2: %s\n", join(', ', sort {$a <=> $b} @shuffle2[0..10]) +;
Output:
shuffle1: 2, 5, 16, 17, 23, 25, 26, 27, 39, 42, 43 shuffle2: 1, 3, 4, 5, 6, 8, 9, 10, 13, 40, 50
This approach is appropriate for the current implementation of uniq, which preserves the original order while removing duplicates.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://618817]
help
Chatterbox?
[Corion]: Yay, vacation time now - one week off work (but a Perl workshop in the middle ;)) )
[talexb]: TStanley I just realized that I was in your area for a convention back in April. We were at the high school for the weekend, the one with the long driveway. Nice spot.
[TStanley]: I am heading to Arlington, Virginia next week, then I get to spend an entire week at home. Looking forward to that as I will have spent 7 weeks on the road by the end of next week
[talexb]: That's a long road trip. I haven't travelled for business in years.

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2017-06-23 14:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (548 votes). Check out past polls.