Zarzal that is incorrect to a degree. The script has a function built in called $forcats
Look for
$forcats ="";
and change to something like this
$forcats ="502,504";
So if you want only specific galleries able to display. You right however this script does just grab a random image from the database which is exactly what it is intended to do. If there are specific things you want included let me know.