or, a bad example for a site like amazon.com, but it works... 😉
you have x amount of images in a dir. use opendir() to open the dir and readdir() to read the files counting them.
Generate a random number between 1 and $filescounted. Start a new counter anddo the above again. If the current counter hits the randomly generated the number, get that images fileinfo and print the image tags.
Kinda...
I use this on my with 5 or so images, just to annoy a coworker. But as Allen wrote, a database should be just a bit better for amazon.com hehe.