Print Page | Close Window

Generating Random Records based on weight

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=3020
Printed Date: 29 March 2026 at 4:30pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Generating Random Records based on weight
Posted By: pmormr
Subject: Generating Random Records based on weight
Date Posted: 25 May 2003 at 8:06pm
I have a script that displays a random record. (basically selects an ad banner from a database) but i'm trying to figure out how to make a record with a weight of 2 display twice as much as a banner with a weight of two. For example if I have 2 banners one with a weight with 1 and the other with a weight of 2 and the script is run 1000 times i want banner 1 to be displayed approximately 333 times and banner 2 to be displayed 666 times. Does anyone have any ideas?

-------------
Paul A Morgan

http://www.pmorganphoto.com/" rel="nofollow - http://www.pmorganphoto.com/



Replies:
Posted By: michael
Date Posted: 25 May 2003 at 9:50pm

You can easily use the builtin ad rotator that comes with IIS. Just create a text file like:
REDIRECT /anyfile.asp
WIDTH 468
HEIGHT 60
BORDER 1
*
http://www.YOUR_DOMAIN_NAME.com/images/banner1.gif
http://www.ADVERTISER1_DOMAIN_NAME.com
Visit Advertiser1 now!
25
http://www.YOUR_DOMAIN_NAME.com/images/banner2.gif
http://www.ADVERTISER2_DOMAIN_NAME.com
Visit Advertiser2 now!
25
http://www.YOUR_DOMAIN_NAME.com/images/banner3.gif
http://www.ADVERTISER3_DOMAIN_NAME.com
Visit Advertiser3 now!
40
http://www.YOUR_DOMAIN_NAME.com/images/banner4.gif
http://www.ADVERTISER4_DOMAIN_NAME.com
Visit Advertiser4 now!
10

where the numbers are the percentages.

Then a simple script to call them:
<%
DIM strBanners
Set strBanners = Server.CreateObject("MSWC.AdRotator")
Response.Write (strBanners.GetAdvertisement("/adrotator.txt"))
%>



-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: pmormr
Date Posted: 26 May 2003 at 10:42am

i think you misunderstood me... what if i want one of those banners to appear twice as much as another.  I already have a management program that counts clicks, shows, etc. but i would like to modify the following lines in the banner selection script

    RANDOMIZE
 Randomno = int((mytable.recordcount * rnd) + 1)
 mytable.absoluteposition = cint(randomno) ' go to the record

so that a record containing a "weight" on 2 will be twice as likely to appear than a banner with a "weight" with 1



-------------
Paul A Morgan

http://www.pmorganphoto.com/" rel="nofollow - http://www.pmorganphoto.com/


Posted By: michael
Date Posted: 26 May 2003 at 5:10pm

I did not misunderstand you; I was just saying that e.g. below, the first one would show abou twice as much as the second one. I don't know how your code looks like right now and your db to tell you how to implement it to your existing script.

http://www.YOUR_DOMAIN_NAME.com/images/banner3.gif
http://www.ADVERTISER3_DOMAIN_NAME.com
Visit Advertiser3 now!
63
http://www.YOUR_DOMAIN_NAME.com/images/banner4.gif
http://www.ADVERTISER4_DOMAIN_NAME.com
Visit Advertiser4 now!
37



-------------
http://baumannphoto.com" rel="nofollow - Blog | http://mpgtracker.com" rel="nofollow - MPG Tracker


Posted By: pedalcars
Date Posted: 27 May 2003 at 6:04am
Or, if you don't want to use IIS's inbuilt rotator, you could simply duplicate the double-weighted banner entry.

ie., you'd have three entries - one for banner 1, and two for banner 2. On a random 1,000 views, banner 1 would get seen around 333 times, as would each of the instances of banner 2. Being identical, banner 2 would therefore get seen roughly 667 times.

Bit of a bodge though, when IIS will do it for you!


-------------
http://www.pedalcars.info/ - www.pedalcars.info

The most fun on four wheels



Posted By: pmormr
Date Posted: 27 May 2003 at 1:03pm
excellent idea... that pretty much what i need. Banner 2 will be twice as likely to be shown as banner one. Good Idea!

-------------
Paul A Morgan

http://www.pmorganphoto.com/" rel="nofollow - http://www.pmorganphoto.com/



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net