Gossamer Forum
Quote Reply
Random repeatas
Hi, Im currently using this random global:

sub {
my $db = $DB->table('Links');
my $total = $db->count ( 'isValidated' => 'Yes' );
my $rand = int( rand($total) );
$db->select_options ("LIMIT $rand, 6");
my $link = $db->select->fetchrow_hashref;
my $html = Links::SiteHTML::display('link', $link);
return $html;
}

But sometimes some links get repeated.
How can I go about fixing this repeat thing?

Thanks,
Juan Carlos
Quote Reply
Re: [Gorospe] Random repeatas In reply to
There's not much you can do about random repeats unless you keep track of which links were already selected.


In any case, this should be a little bit better than what you currently have:

Code:
sub {
my $db = $DB->table('Links');
$db->select_options ("ORDER BY RAND()", "LIMIT 1");
my $link = $db->select->fetchrow_hashref;
my $html = Links::SiteHTML::display('link', $link);
return $html;
}

Philip
------------------
Limecat is not pleased.
Quote Reply
Re: [fuzzy logic] Random repeatas In reply to
Okay, Ive implemented it and works fine so far. I guess Ill have to wait and see how it performs on a regular basis... Thanks.