Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
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 imbibing at the Monastery: (6)
As of 2014-09-20 18:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (160 votes), past polls