Where do you see that he saves anything?

I'm not sure what you are asking there. I have the %numbers hash, exactly equivalent to your %NoDups, in which I save the random numbers. This statement

$numbers{ int( rand 20 ) + 1 } ++

generates a random integer between 1 and 20 inclusive which is used as a key into the %numbers hash, the value associated with that key being incremented.

His loop handling is definitely non-Perl.
while keys %numbers < 10;

Nonsense! The while statement modifier is a standard Perl looping construct and will repeat the $numbers{ int( rand 20 ) + 1 } ++ statement until there are ten key/value pairs in %numbers, the keys being the unique random numbers.

He could just have done:
for ( 1..10 )

No, that would only yield ten numbers if no random number was repeated during the ten iterations. If there was one repeat there would only be nine numbers, only eight if two repeats etc.

Could you explain further why you think the code I posted is incorrect as I don't quite understand your objections.

Update: Added comment regarding use of for ( 1..10 ).

Cheers,

JohnGG


In reply to Re^6: Perl - Unique Numbers by johngg
in thread Perl - Unique Numbers by deelinux

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.