your query will need to return the galley id and image size as well:
SELECT CONCAT(gallery_id,'/',file_prefix,'_782p.', file_ext) as fileName
FROM pg1_gallery_images
ORDER BY Rand() LIMIT 1
then in the image tag, add the relative path to the images folder:
<img src="images/<?php echo $row_RecordsetName['fileName']; ?>" />