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 musing on the Monastery: (6)
As of 2014-09-18 22:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

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











    Results (125 votes), past polls