a wee weblog, since 2006

Adding randomness to almost anything

11Jun
2006

I was looking for a simple way to display a random image on the head of this site and i think i found the simplest/easiest solution out there.

It uses php to spit out a number between a high and low that you set. For example, if you have a series of 5 images and you want any one of those to appear randomly when a page is loaded, here’s what to do:

name each image 1.jpg, 2.jpg etc.(or whatever1.jpg, whatever2.jpg) and upload to your location.

Enter the following html/php into wherever you want the image to display:

<img src=“/path/to/image/<?php echo rand(1,5) ?>.jpg" />

the ‘rand(1,5)‘ is your lower and higher variable, in this case the script spits out a random number between 1 and 5 into the image path.

sweet eh

As captured 13 September 2007 · The archived original