

Random Image Generator
Using a random image generator on your website has many practical purposes, some of which include creating a rotating banner system or rotate advertising ads. Its a valuable piece of code on your website and this tutorial will show you a simple way to use it.
<?php
$images = 5;
$path = "images/";
$random = rand(1,$images);
echo "<img src=$path"."$random".".jpg".">"
?>
$images = 5;
This is where we define the number of images that will be displayed. If the number is larger than the number of images in your folder you will get nothing back on certain refreshes. If you put the number smaller than the number of images in your folder, you will only display images up to that number. The images must be named in numerical sequence so if you put the number at 4 and have 5 images, the #5 image will not be displayed.
$path = "images/";
This is where you define the path to your images folder
$random = rand(1,$images);
Here we use teh rand() function to create a random number starting from 1 and ending at the number defined in our "images" variable
echo "<img src=$path"."$random".".jpg".">"
Here we piece everything together and echo out the image. Note if you have any other extension than .jpg you will have to change it in this line.
The script in action












