
Recently, while developing a site, I ran into a need for the ability to select 4 random images from a folder and display them in a div container. I searched around and found several scripts that would pull single random images (I’ve used this simple script from Matt Mullenweg’s site several times, for example) but nothing that would randomize multiple images. As I often do when I run into a brick wall, I tweeted about my problem and received a response from James Paden of Xemion.com* offering to write the script for me for free! The kindness and generosity of people I have met through blogging and Twitter continually amazes me.
He based the multi-image script on this single random image script, and it works great! Since I had such a hard time finding one I thought (with James’ permission) that I would make it available here. It’s set up to call 4 images, but shouldn’t be too hard to tweak for the number you need.
Click here to get the code and instructions.
Thanks again to James for helping me out!
*Xemion.com is a great resource for small business owners and managers to both find web designers and learn how to best hire and work with design firms.


















A nice implementation, but as ever with PHP there’s about a hundred different ways to do it. That in itself can be confusing, but if you’ve got the time it’s well worth learning the basics. I’ve developed using PHP for nearly five years, but I still come across things I’ve never seen before!
very useful script! great post
thank you for sharing
Useful and much appreciated for sharing.
Thanks Randa and James!
I can already think of a couple of places this script will come in handy. Thanks for finding it and posting!
I used a script like this on a fishing site I once owned. It makes the page look fresh by serving up a different image each time the page is loaded.
Great script, just what I needed. Thx for sharing.
Being a non-geek my eyes usually glaze over when I see letters like php and words like div container. The demo made all the difference however.
It is certainly cool and gets even a blogger with no computer background like me to really want to try it.
I can see using a code like this for making a spash screen for your site.
It’s an easy database pull. That’s what PHP is for. I’m not to savvy when it comes to writing scripts, so any little bit would help. Anyways, I’ve been working on a new project for a feed for images. This script will definitely be a good source-view for breaking down the code and messing with it.
Great srcipt Randa, it was very kind of James to write it for free! Thanks for sharing it with us.
great post. thanks for sharing Randa
Hi Randa, thanks for sharing the info with us. I’m new to PHP and I’m looking to implement this into my own website. The single random image script might just work for what I want.
The PHP Script is great. I have seen a WordPress Theme which have a header at top and the image change at every page load. Now I know, it is possible through some php coding like the one shown here.
Great helping post. I have saved the txt code with myself for use in future