View Full Version : random image without repeat

07-03-2008, 06:45 PM
I have a script working that displays a set of random images, but how in the world do I get it to not repeat an image?

My script displays a list of 5 images at a time, and I would like to not repeat an image in a group. any ideas?

07-04-2008, 06:35 AM
It would depend upon the rest of the code, but some sort of test would need to be applied to the random selection process to see if a duplicate has been selected. And a routine that would continually supply alternative selections until a non duplicate was selected would need to be devised.

This can get tricky in actual practice, especially if the image pool (selection opportunities) is small, because it will (if not efficiently constructed) lead some browsers to believe that you are causing the type of endless code loop that sets of an alert to that effect.

Please post a link to the page on your site that contains the problematic code so we can check it out.