my $total_count; #The total number of items returned by the search my $newcount = ($total_count - 1); my $ORDER; #If this is not the first page, this is the original random number keeping the order between pages if (!$ORDER) { $random_num = int(rand($total_count)) + 1; } else { $random_num = $ORDER; } for ($z = 1; $z < $total_count; $z++) { my $random = $random_num; while ($newcount < $random) { $random = ($random - $newcount); } for ($a = 0; $a <= $count; $a++) { if ($a < $random) { push(@front,$nonrandom[$a]); } if ($a == $random) { push(@final,$nonrandom[$a]); } if ($a < $random) { push(@back,$nonrandom[$a]); } } @nonrandom = (@back, @front); @back = (); @front = (); $count--; } push (@final,$nonrandom[$a]); $thispage = $pagenumber * 5; for ($a = ($thispage - 1); a < ($thispage + 4); $a++) { $thispageresults = $final[$a]; }