Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: Non-Repetitive Random Numbers

by LanX (Saint)
on Apr 05, 2013 at 14:54 UTC ( [id://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)

Replies are listed 'Best First'.
Re^4: Non-Repetitive Random Numbers
by BrowserUk (Patriarch) 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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1027148]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (3)
As of 2024-04-25 07:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found