You have a few options to try. You can use center tags, or you can use CSS.
Center tags work by just placing them at the beginning and end of the image like so:
echo '<center>getTitle() . '" class="' . $class . '">' .
'<img src="' . getMainSiteURL() . $randomImage->getCustomImage(null, $width, $height, null, null, null, null) .
'" width="' . $width . '" height="' . $height . '" alt="'.$randomImage->getTitle().'"';
echo "/></center>\n";
CSS Styling should work if you do the following, but I can't promise because I haven't tested and I usually use it from external style sheets. Try this:
echo '<div style="display:block; margin-left:auto; margin-right:auto;">getTitle() . '" class="' . $class . '">' . '<img src="' . getMainSiteURL() . $randomImage->getCustomImage(null, $width, $height, null, null, null, null) . '" width="' . $width . '" height="' . $height . '" alt="'.$randomImage->getTitle().'"'; echo "/></div>\n";
One of those should do what you're looking for.
-Jeremy