Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW

Re^3: Non-Repetitive Random Numbers

by LanX (Chancellor)
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.


> 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)

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
Replies are listed 'Best First'.
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?

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2015-11-29 10:33 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (750 votes), past polls