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 (Hermit)
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 examining the Monastery: (3)
As of 2014-07-10 03:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (198 votes), past polls