I decided to make it an answer.
FYI ... You are missing one of your photos in the first version, fyi.
I would go with 2. 1 loads all the images in front (more useful if you change images by doing things from the slide show). Thus, it uses high bandwidth and slows down page loading.
2 looks fine, but I can change pickRandom (ic) to pickRandom (xoxo.length), so you donβt have to forget about updating ic when adding more images.
You might want to create a cookie for the user (lastImageIndex) to iterate over the elements. If cookies are not available, just use a random image. Otherwise, start with an arbitrary image. Then each time accessed using a cookie increment. When you reach the length, return to 0.
function getCookieValue(choice){ // read cookie here, if found, parseInt(cookieValue,10) and assign to choice // Then return choice (either original value or updated) return choice; } var choice = pickRandom(xoxo.length); choice = getCookieValue(choice); // Check if it correspond to an image if (choice >= xoxo.length) choice = 0; // Store the cookie here. Store choice++
This description is a little different from what you asked for as it is per user, but I would say that it gives you more of the result you are looking for.
source share