Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re^3: Non-Repetitive Random Numbers

by LanX (Canon)
on Apr 05, 2013 at 14:54 UTC ( #1027148=note: print w/ replies, xml ) Need Help??


in reply to Re^2: Non-Repetitive Random Numbers
in thread Non-Repetitive Random Numbers

I don't understand your point (and I'm too much in a hurry ATM to investigate your code)

Keys of a hash are always unique, in my code collisions of random numbers are simply ignored.

update

> That doesn't guarantee unique values.

maybe this is clearer:

DB<107> $seen{int rand 10}=1 for 1 .. 1000000 => "" DB<108> keys %seen => (6, 3, 7, 9, 2, 8, 1, 4, 0, 5)

update
one could argue that the order of hash -keys isn't random but that wasn't part of the question.

Otherwise thats a good occasion to use shuffle or pushing into an array (but this implies reseeding rand every time)

Cheers Rolf

( addicted to the Perl Programming Language)


Comment on Re^3: Non-Repetitive Random Numbers
Select or Download Code
Re^4: Non-Repetitive Random Numbers
by BrowserUk (Pope) on Apr 05, 2013 at 15:24 UTC
    Keys of a hash are always unique,

    You're right of course.

    I was thinking about an iterator which would need to check whether a value had been seen before but ...


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1027148]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2015-07-03 22:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (57 votes), past polls