Show related images in single image view

This code snippet will show random other images from the same gallery when viewing a single image.

Please note this will not work with Lightbox.