<%@ Language=VBScript %>

' set checking on so that we have to dimension our variables before we can use them
Option Explicit

' dimension our variables first
dim filesys, folder, folder_name_web, folder_name_drive, files_collection, filecount, filename, rand, file, i

' store the images directory name in a variable
folder_name_web = "rotating_images/"

' map the folder name as accessible through the web to the actual path on the hard-drive.
folder_name_drive = Server.MapPath(folder_name_web)

' create a FileSystem Object and use it to get a Folder Object
set filesys = CreateObject("Scripting.FileSystemObject")
set folder = filesys.GetFolder(folder_name_drive)

' get a collection of all the files in the folder
set files_collection = folder.Files

'get the number of files in the collection
filecount = files_collection.Count

' generate a new seed for the Rnd() function

' generate a random number between 0 and filecount - 1
rand = Int(Rnd() * filecount)

' get the name of the file corresponding to the random number
i = 0
for each file in files_collection
	filename = file.name
	if i = rand then exit for
	i = i+1

' output the html

<title>Rotating Images</title>

		<td><img src="<%=folder_name_web%><%=filename%>"></td>
		<td>Refresh the page to see a randomly chosen image.</td>