That looks correct. You should probably also seed the random number
generator. I'm not sure if you need to do this every time the code is
called, but it can't hurt. Make sure you run a large test of the code's
"randomness" before you conclude whether it works or not. Just create a
loop that calls (or includes) the code and note the frequency of each ad.
One thing I'd change, to save the calls to the ValueList() function:
<cfset bid = q_banners.BannerAdID[RandRange(1, q_banners.recordcount)]>
A simple frequencty test loop:
<cfset freq = StructNew()>
<cfloop index="i" from="1" to="50000">
<!---
Place your code here
--->
<cfif StructKeyExists(freq, "#bid#")>
<cfset freq[bid] = freq[bid] + 1>
<cfelse>
<cfset freq[bid] = 1>
</cfif>
</cfloop>
<cfloop item="bid" collection="#freq#">
<cfoutput>#bid#: #freq[bid]#</cfoutput><br>
</cfloop>
Jim
-----Original Message-----
From: Duane Boudreau <[EMAIL PROTECTED]>
To: CFTalk <[EMAIL PROTECTED]>
Date: Sunday, July 23, 2000 2:50 PM
Subject: Random Numbers and Banner Managers
>Hi All,
>
>I'm working on a banner manager program and I seem to be having a problem
>getting a true random number. It seems that some of the banners pop up
more
>frequently than others. Here is the code I am using. Is there something
>better I could be using to generate a random number or is this as good as
it
>gets?
>
><cfquery datasource="#Attributes.DataSource#" name="q_banners">
> SELECT BannerAdID
> FROM BannerAds
> WHERE Active = 1
></cfquery>
><cfset variables.bid = ListGetAt(ValueList(q_banners.BannerAdID),
>andRange( 1, ListLen(ValueList(q_banners.BannerAdID))))>
>
>TIA,
>Duane Boudreau
>CFExperts.Com
------------------------------------------------------------------------------
Archives: http://www.mail-archive.com/[email protected]/
To Unsubscribe visit
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.