#!/usr/bin/perl -w use strict; srand(); my @array1=(); my $Max_Questions = 30; #Will vary upon how many questions #the person wants to answer my $ref = random(\@array1,$Max_Questions); sub random{ my $array = shift; my $Max = shift; my $lines = 100; #There is a function that gets the #number of lines in the actual data #file, but there will be at least 100. my $num = int(rand($lines)+1); push(@$array,$num); my $length = @$array; my $backcheck = 0; while($length != $Max){ my $numcheck = $num; $num = int(rand($lines)+1); if(($numcheck != $num) && ($num != @$array[$backcheck])){ push(@$array,$num); $length += 1; $backcheck = $length-2; } } my @sorted = sort {$a<=>$b} @$array; print"Element\t\tUnsorted\tSorted\n"; print"-------\t\t--------\t------\n"; for(my $z = 0;$z<$Max;$z++){ print" $z"; print"\t\t @$array[$z]\t\t"; print" $sorted[$z]\n"; } } #### Element Unsorted Sorted ------- -------- ------ 0 83 2 1 99 9 2 63 23 3 24 24 4 41 27 5 2 28 6 72 29 7 65 33 8 33 39 9 27 40 10 85 41 11 78 41 12 94 46 13 96 47 14 84 58 15 58 61 16 29 63 17 28 65 18 68 68 19 71 71 20 41 72 21 97 78 22 88 83 23 9 84 24 40 85 25 39 88 26 61 94 27 46 96 28 23 97 29 47 99