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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Decision based on percentage

Status
Not open for further replies.

mike2312

IS-IT--Management
Aug 27, 2003
38
US
I am unsure of where to ask this. I guess since the implementation will be in ASP im landing it here.

I need some form of percentage based decision making algorithm.

What I am going to do is have a set of percentages in a SQL database....based on those percentages there I want to do something.

Example:

Action A: 40%
Action B: 20%
Action C: 25%
Action D: 15%


so basically I want action A performed 2 out of 5 times, Action B performed 1 out of 5 times, Action C I want to happen 1 in four times, and so on.

There can be N number of actions with percentages totaling 100%.

I have seen a recommendation of using the MSWC.ContentRotator which I am looking into. I have also seen a recommendation of using a string vector, then index into it using modulo.

If I were to use the string vector, and still wanted to support percentages that are not multiples of ten then my string vector would contain 100 indexes, and it would not be possible to do a round robin on this...

Help please.
 
<%
randomize
seed = int(rnd*100) + 1

SQL1="SELECT percentage,action from mytable order by percentage"
Set RS1 = myConn.execute(SQL1)
While not RS1.EOF
if seed < RS1("persentage") then action = RS1("action")
RS1.movenext
wend
set R1 = nothing
myconn.close
Response.write "Action = " & action
 
Sorry about the previous post. It was late and I forgot a piece where you need to add the percentages together and to end the while once the action is found. Try:

<%
randomize
seed = int(rnd*100) + 1
percentage=0
SQL1="SELECT percentage,action from mytable order by percentage"
Set RS1 = myConn.execute(SQL1)
While not RS1.EOF
percentage = percentage + RS1("percentage")
   if seed < percentage then
action = RS1("action")
RS1.movelast
end if
RS1.movenext
wend
set R1 = nothing
myconn.close
Response.write "Action = " & action
%>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top