(editing what I wrote originally)
I found the spot where there is similar code, but it's not exactly what you posted. Here's what I have:
default:
if ( !isset($cat) || empty($catquery) ) {
$group_title = "{$Globals['pp_lang']['random']}";
$query = "SELECT id,user,userid,cat,storecat,title,bigimage,views,height,width, id*0+RAND() as rand_col FROM {$Globals['pp_db_prefix']}photos WHERE approved='1' $exclude_cat ORDER BY rand_col DESC";
break;
}
else {
$group_title = "{$Globals['pp_lang']['random']} - $catname";
$query = "SELECT id,user,userid,cat,storecat,title,bigimage,views,height,width, id*0+RAND() as rand_col FROM {$Globals['pp_db_prefix']}photos WHERE approved='1' $userq $exclude_cat AND cat in ($catquery) ORDER BY rand_col DESC";
-----------------------
There's no 'LIMIT $grabnum";' stuff - so I'm not sure where to put the code you gave.
Sorry - I'm (obviously) not good with code and do REALLY appreciate your time!