I don't think this will work well.... Yes, you have listed the banner ID's in the proper percentage, but there is no guarantee that the random number will match that weighting.
For instance, a random number generator could (in theory) produce "1,1,1,1,1,1,4,5,1,1". Now, if the ID at position 1 was weighted for 10%, they are really getting more than 10% in this case. The problem being that you can't rely on a random number to pick the weighted elements. A different option would be to maybe do like Ben mentioned below in creating a list or array of the elements, but randomly distribute the IDs within the Array (you've already determined how many there should be of each ID based on the weight). Then, you just need to loop through the list or array, showing the next element. This would result in the proper weighting, I think. Then again, I've never had to worry about rotating banners - but I'm normally good at finding holes in solutions (sorry Ben). Shawn Grover -----Original Message----- From: BEN MORRIS [mailto:[EMAIL PROTECTED]] Sent: Tuesday, March 05, 2002 11:35 AM To: CF-Talk Subject: Re: Rotating banners I would think that you would loop through your query, and build a list. For each query record, loop from 1 to the weight value, and add the bannerID to the a list called bannerIDList for each nested loop. This way if you have one banner with bannerID=301 and weight=2, and a second banner with bannerID=302 and weight=10, the list would look like: "301,301,302,302,302,302,302,302,302,302,302,302" Then you could pull a random ID from this list and run the query. >>> Elizabeth Walter <[EMAIL PROTECTED]> 03/05/02 01:14PM >>> Hello- I am developing a banner rotating tool and need some ideas on how to best handle a requirement. I have gotten the tool to a point where it displays banners randomly- no problem. Now what I need to do is give certain banners more "weight" than others: some banners need to be displayed more frequently than the rest. The code that I have below gives equal weight to each banner; I need to find a way to give some banners more prevalence on our pages. <cfset activeBanners=arrayNew(1)> <cfoutput query="qryActive"> <cfset activeBanners[#qryActive.currentRow#] = "#id#"> </cfoutput> <cfset rows = arrayLen(activeBanners)> <cfset randomId = randRange(1,#arrayLen(activeBanners)#)> <cfquery datasource="#dsn#" name="qryBanners"> SELECT i.*, a.advert_name FROM images i, advertiser a WHERE i.id = #activeBanners[randomId]# and i.advert_id = a.advert_id </cfquery> Any ideas? Thanks in advance, Elizabeth ______________________________________________________________________ Dedicated Windows 2000 Server PIII 800 / 256 MB RAM / 40 GB HD / 20 GB MO/XFER Instant Activation · $99/Month · Free Setup http://www.pennyhost.com/redirect.cfm?adcode=coldfusiona FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Archives: http://www.mail-archive.com/cf-talk@houseoffusion.com/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists