#! perl -slw use strict; sub distinct_random_int{ my($num, $start,$end) = @_; my %uniq; $uniq{ $start + int( rand $end-$start ) } = undef while keys %uniq < $num; return keys %uniq; } print for distinct_random_int 10, 20, 30; __END__ P:\test>388533 27 25 28 21 26 20 22 24 23 29