Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Is there a better way to generate unique set of random numbers ?

by FloydATC (Chaplain)
on Jul 29, 2011 at 21:50 UTC ( #917553=note: print w/ replies, xml ) Need Help??


in reply to Is there a better way to generate unique set of random numbers ?

I have another suggestion that would seem slightly more linear than stabbing away at a %seen hash:

my @numbers = (1 .. 10); while (@numbers) { my $index = rand(@numbers); my $pick = splice(@numbers, $index, 1); print "$pick\n"; }
Edit: The first version had an off-by-one error :o)
-- Time flies when you don't know what you're doing


Comment on Re: Is there a better way to generate unique set of random numbers ?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (13)
As of 2014-12-22 16:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (121 votes), past polls