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