kbeen has asked for the wisdom of the Perl Monks concerning the following question:
Although my solution this time is fine this time, I am sure someone knows a cool way to get truly random results, and pass the same randomness between pages in a CGI script.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 ran +dom 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]; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Predictable Randomness
by Masem (Monsignor) on Aug 11, 2001 at 22:04 UTC | |
by trantor (Chaplain) on Aug 13, 2001 at 21:02 UTC | |
by tilly (Archbishop) on Aug 13, 2001 at 21:09 UTC | |
|
Re: Predictable Randomness
by traveler (Parson) on Aug 12, 2001 at 02:55 UTC |