Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
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 lurking in the Monastery: (4)
As of 2016-08-30 07:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The best thing I ever won in a lottery was:















    Results (411 votes). Check out past polls.