Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Random Image

Status
Not open for further replies.

jackyl

Programmer
Oct 23, 2001
44
CA
I am making a document that has to draw upon a pool of images to display.

I have 6 pools of 4 images. Each pool will be used for a different section of the site. So, I need to identify what pool I need to draw from, and than pick one of the 4 images at random to display.

The images in each pool are named similar.

(business1.jpg, business2.jpg, bisiness3.jpg, business4.jpg)
(about1.jpg, about2.jpg, about3.jpg, about4.jpg)
etc.

any suggestions.

 
Sure... a little rand() magic.

Something like:

Code:
<CFSET randseed=randomize(DatePart(&quot;s&quot;,Now())*10000)>
 
<CFSWITCH expression=&quot;#RandRange(1,6)#&quot;>
   <CFCASE value=&quot;1&quot;>
	<CFSET imgpool = &quot;business&quot;>
   </CFCASE>
   <CFCASE value=&quot;2&quot;>
	<CFSET imgpool = &quot;about&quot;>
   </CFCASE>
       :
      etc

</CFSWITCH>

<CFOUTPUT><IMG SRC=&quot;/whateverdirectory/#imgpool##RandRange(1,4)#.jpg&quot; etc etc /></CFOUTPUT>

... adjust accordingly.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top