Display random image

I'm in the process of making some new banners for the top of the blog and want one to show up randomly. I did this on a site I made for the Anime Group at college. So I found that code first

<cf_count>
<cfset num = randrange(1,x)>
<cfoutput>
   <img src="anime#num#.jpg">
</cfoutput>

count.cfm

<cfset caller.x = 5>

WTF, did I seriously have another file that I used just to tell me the number of banners I have? LOL, I suck. Well I'm not going to copy that crap to here. Here's some code that can be compressed to two lines and will randomly show any image in the given folder. Though I must admit, my old method was faster, since it wasn't lugging around a cfdirectory tag. But not like I'll have 10k banners and not like my blog gets any real traffic.

<cfdirectory
   action="list"
   directory="#ExpandPath('assets\banners')#"
   name="dir"/>

   
<cfoutput>
   <img src="assets/banners/#dir.name[RandRange(1,dir.recordcount)]#" alt="" />
</cfoutput>

Comments
"great minds think alike" or "gooey minds think alike"? Murlocs are a gooey folk :)
# Posted By Murloc Oracle | 6/9/08 2:14 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.002. Contact Blog Owner