my dog learned polymorphism*
The moose likes Java in General and the fly likes To control the display of different items on varying periodicity for a web applicatio Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "To control the display of different items on varying periodicity for a web applicatio" Watch "To control the display of different items on varying periodicity for a web applicatio" New topic
Author

To control the display of different items on varying periodicity for a web applicatio

Smitha S Nair
Greenhorn

Joined: Apr 25, 2007
Posts: 1
We need to implement a logic for a web application where in we need to control the display of some items with varying frequency/percent. For eg. let us say I need show an ad a specific percentage of users. There might be different products under different brands and I have to maintain a certain percentage for the combination of brand/product. I could define the percentage for each brand/product in an XML/properties file. The question is how to ensure the ads do stick to this.

One way would be to maintain an application wide session to track the user counts and maintain a brand/product combination ad hit to ensure a certain percentage/number.

But with a growing number of brand/product combination, the session object might get too huge to manage and also might affect the performance

We also tried to use random number and check agains a specified percentage and determine if the current session falls under this percentage (A sample program below). But there was a variation of about 10%.

Please suggest if you are aware of a better logic of achieving this, so that more accurately stick to the percentages.

This is the sample code we tried, please note that the count below is just an indicative one which would be replacing the actual code and hence cannot be used to tweak to stick to the percentage.

public class TestRandomTwo{
public static void main(String args[]) {
int countA = 0;
int percentA = 30;
int countB = 0;
int percentB = 100;
int countC = 0;
int percentC = 50;

for(int i=0;i<100;i++) {
int rand = (int)(Math.random()*100);
if(percentA>=rand)
countA ++;
if(percentB>=rand)
countB ++;
if(percentC>=rand)
countC ++;
}
System.out.println("count beyond "+percentA+"% = "+countA);
System.out.println("count beyond "+percentB+"% = "+countB);
System.out.println("count beyond "+percentC+"% = "+countC);
}
}
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Hi, welcome to the ranch!

But there was a variation of about 10%.


Yup, random does not guarantees a perfect distribution. Delivering add x on exactly n% of page displays is impossible. After one sample it will be 0% or 100%. Oh my!

I have used a scheme with "weights" instead of percentages. You could buy more weight, but if your competitor buys the same amount the percentage might be 50%. I was trying to encourage weight building wars.

Can that work?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: To control the display of different items on varying periodicity for a web applicatio
 
Similar Threads
Battleships - guys please help me out!
javax.crypto.BadPaddingException - not using strings
equals compares the wrong things
Random insert and delete into an arraylist
Creating simple GUI interface for BattleShips