Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

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

by FloydATC (Deacon)
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 all is quiet...

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2017-07-25 23:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I came, I saw, I ...
























    Results (383 votes). Check out past polls.