Remove the limit from the getIntTableRows that loads the $thumb array.
Add a variable $pic and make it equal to rand(0,count-1).
Find the line with $thumb[0]['filename'] and replace the 0 with $pic.
Here is the patched section if you just want to copy and paste.
foreach($children as $child) {
$thumb=$etomite->getIntTableRows("filename", $gtable, "gal_id='" . $child['id'] . "'",$order_by,$order_direction);
if($thumb[0]['filename']=="") continue;
if($number_in_row==0) {
$returnstring.="<tr>";
}
$childself = "index.php?id=".$child['id']; //MF removed use of alias
$pic=rand(0,count($thumb)-1);
$returnstring.="
<td align=\"center\" style=\"width:" . floor(100/$pics_in_a_row) . "%\">
<a href=\"".$childself."\">
<img src=\"".$path_to_galleries.$child['id']."/tn_".$thumb[$pic]['filename']."\" class=\"EGthumbnail\" title=\"" .$strings['go_to_gallery'] . "\" alt=\"" . $strings['go_to_gallery'] . "\" />










