in reply to Trying to get sum of elements in array

About filling up your array... you're using a random index number and will only stop if there are 5 different indexes, possibly looping more than 5 times. I find the following much more clean: It only loops 5 times, for sure:
my @list = (); foreach my $i (1..5) { push @list, int(rand(50)+1); }
--
if ( 1 ) { $postman->ring() for (1..2); }

Replies are listed 'Best First'.
Re^2: Trying to get sum of elements in array
by LanX (Saint) on Feb 06, 2015 at 12:38 UTC
    But the result isn't guaranteed to be unique.

    If you worry about performance rather use a shuffle approach.

    Or use the fact that the order of keys in a hash is random.

    Cheers Rolf

    PS: Je suis Charlie!

      Why do these random numbers have to be unique?
      --
      if ( 1 ) { $postman->ring() for (1..2); }
        We've already established that this is a homework assignment. Perhaps uniqueness is one of the assignment's constraints?