Forum Moderators: open
i.e.
action 1 happens 70% of the time
action 2 happens 20% of the time
action 3 happens 10% of the time
how do you calculate when a certain action should happen, if it's getting out of percentage?
-Matt
start a counter at 0
increment counter each use
save counter to application variable
use (counter modulo 10) as an index into the vector
1111111223
to determine which action to take,
notice there are
7 x action 1
2 x action 2
1 x action 3
which are your desired proportions
this is EXTREMELY scalable
// application level
// set %ages
action1=10;action2=20;action3=70;
// create a 2-column structure
actions()=new map;
// page level
// get current action
x=thisAction();
// record action name and increment counter
actions(x).value() ++;
// work out the total number of actions
for i=actions.start()...actions.end()
{
total= total + actions[i].value()
}
// tests will be something like this
// standard %age calculations
if ( actions("action1").value() / total * 100 < action1 )
{
// action1 is below 10%
}
[w3schools.com...]
Select Case adrot.GetAdvertisement("ads.txt")
Case ...
End Select
that may be what i'm looking for.
i'm building a page that when a user visits it, the page will redirect to other specfied pages, based on the weight. i just need to figure out how i'm going to get the redirects to work. that's why i was looking for an asp-based algorithm, so i didn't have to worry about text files.
-Matt
making the text file an asp file is allowable, but it doesn't render the ASP into text.
here's my setup:
rotator.asp-
<%
dim cr
Set cr=Server.CreateObject( "MSWC.ContentRotator" )
%>
<P><%=cr.ChooseContent("rotatortxt.asp")%></P>
rotatortxt.asp-
%% #1
<%="works"%>
%% #2
<%="works"%>
%% #3
<%="works"%>
%% #4
<%="works"%>
here is the output when i call rotator.asp (asp tags are not being rendered):
<P><%="works"%>
</P>
any ideas?
-Matt
Get frequency and url rows from database
for i = 0 to rs.count
for j = 0 to thisrow.frequency
randomize a key
add the key and the url into a dictionary object
next
next
Sort Dictionary based on key
Load Dictionary data values into simple array
Load array into application variable
To get the random stuff:
randomize a number from 0 to array.length -1
response.write array(newRandomNumber)