#! perl -slw use strict; use List::Util qw[ shuffle ]; sub distinct_random_int{ my($num, $start,$end) = @_; return ( shuffle $start .. $end )[ 1 .. $num ]; } print for distinct_random_int 10, 20, 30;