Results 1 to 2 of 2

Thread: random image without repeat

  1. #1
    Join Date
    Jul 2008
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default random image without repeat

    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?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,074
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •