#!/usr/bin/perl my @arr = (); my $counter = 1; for($i=0; $i<32; $i++) { while(1) { $rand = int(rand(32)); # print "testing: $rand\n"; if (grep(/$rand/, @arr) == 0) { print "$counter: $rand\n"; push @arr, $rand; $counter++; last; } } } #### $ ./create_random_numbers.pl 1: 29 2: 20 3: 27 4: 31 5: 25 6: 21 7: 19 8: 13 9: 26 10: 12 11: 8 12: 28 13: 11 14: 16 15: 22 16: 17 17: 4 18: 10 19: 23 20: 18 21: 24 22: 15 23: 14 24: 30 #### #!/usr/bin/perl my @arr = (); my $counter = 1; my $range; for($i=0; $i<$range; $i++) { while(1) { $rand = int(rand($range)); if (grep(/^$rand$/, @arr) == 0) { print "$rand\n"; push @arr, $rand; $counter++; last; } } }