Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

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

by chakreey (Acolyte)
on Jul 28, 2011 at 09:58 UTC ( #917235=note: print w/replies, xml ) Need Help??


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

Thank you

I am still a beginner in perl, can you help me understand $seen{$candidate}++ in line:

redo if $seen{$candidate}++;

Replies are listed 'Best First'.
Re^3: Is there a better way to generate unique set of random numbers ?
by moritz (Cardinal) on Jul 28, 2011 at 10:02 UTC
    %seen is a hash. If the key $candidate is not present in the hash, it is added to the hash (that's called "autovivification"), initialized to 1, and undef is returned - the redo is not executed.

    On the other hand if the key is already present in the hash, the corresponding value (for example 1) is returned, and incremented by one (for example set to 2). In this case the interesting part is not the incrementing, but that it returns a true value, so the redo is executed.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://917235]
help
Chatterbox?
shmem often walks around searching his glasses. In order to have a better sight, I put them on.
[Discipulus]: I'm advantaged: berrillio is always on my noose
Discipulus looks for his glasses just to defeat his thirst

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2018-05-20 16:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?