Page 1 of 1

Looking for Random Image Solution

Posted: Tue Oct 10, 2006 8:41 pm
by Patow
I'm looking for a Random image solution (PHP/HTML) where I have a page with a table (say 5 x 5), and I want a random image displayed in each table cell. There are a couple of caviats:

1) I don't want duplicate images in the table
2) I want the photos to be thumbnails, and have them link to the source file
3) I'm hoping to have a scalable solution so I can have tables bigger than 5 x 5 without duplicate files, and without a ton of manual labour to add new pictures to the mix.

Can anyone point me to an existing documented solution?

Thanks,

Dave

Posted: Tue Oct 10, 2006 9:26 pm
by ambivalent
Off the top of my head, you'd have your thumbs in an array and use shuffle or maybe array_rand to pick out the thumbs to display.

Search this forum for "random image", this has been discussed before and you should turn up a few ideas.

Posted: Tue Oct 10, 2006 9:47 pm
by nickvd
pseudo code:
  • get image file names into an array
  • randomize the array
  • randomly pick a value from the array
  • check if the filename picked from the array is not in the second array
  • put that filename into a second array that holds the filenames already picked
  • display the image
  • wash
  • rinse
  • repeat