Another approach that might work would be to do the math first and to slightly alter the query syntax:
$totalNeeded = 60; // total results needed/wanted
$divisor = 3; // modulus divisor
$range = range(0, ($totalNeeded * $divisor)); // numbers used in query before filtering
$counter = 1;
// filter the numbers in your array:
foreach($range as $key=>$value)
{
if($counter > $totalNeeded) unset($range[$key]);
elseif($value % $divisor != 0) unset($range[$key]);
else $counter++;
}
// use the "IN" clause for your query:
$query = "SELECT id
FROM myTable
WHERE program_id IN(" . implode(',', $range) . ")";
Of course, this may become very unwieldy for very large results needed, but with pagination, and keeping result sets less than 100, it should be ok... me thinks.
The reason why I like this, is that you will not select anything from the DB that you will not end up displaying on the page.