my @items; while (1) { my $item = $a[ rand @a ]; push @items, $item unless $item ~~ @items; last if $n <= @items; }