while ( @results < $num ) { if ( (@$array - $pos) * rand() < $num - @results ) { push @results, $array->[$pos]; } $pos++; }