#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    73
    Rep Power
    14
    Anyone knows/suggests the logic to get a random number with some specific weights?
    A clear example: banner serving, from a banner pool, you get a banner, and that banner has a weight.
    One solution I've seen: create an array with the heavier elements have more copies in the array.

    So that: a banner with weight 10 and there are 10 other banners with weight 1, the pool banner will have 11 elements, and the banner with weight 10 appears 10 times!

    What I want to ask is another solution(or algorithm)? Or is this one the best algorithm?

    ------------------
    http://new.123finder.com/ - Helps you find cool domains for FREE & Registers it for only $14.95/yr
    http://www.guideclick.com/ - Qualified webmaster resources (affiliate programs, web design, tips)

    ------
    Son
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Posts
    45
    Rep Power
    15
    Yes, that probably is the best way - I can't think of any other way to generate a weighted random number. A lot depends on a case-to-case basis, but this is probably the best general way.

  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    Portland, Or USA
    Posts
    3
    Rep Power
    0
    you could loop on each banner by the number of the weight you want to give it. For example if I want to give:
    Banner A = 10
    Banner B = 7
    Banner C = 1
    Loop on banner A 10 times and keep the largest number by comparing the first and second number...keep the largest...compare against the 3rd...keep the largest and so on.

    loop on B 7 times and keep the largest number

    loop on C only one time.

    The A, B or C with the largest number gets to be the banner posted.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Posts
    73
    Rep Power
    14
    Is that efficient? I mean the speed? You used quite a lot of loops, and that thing would effectively decrease its speed, and put more work on the web server


    ------------------
    http://new.123finder.com/ - Helps you find cool domains for FREE & Registers it for only $14.95/yr
    http://www.guideclick.com/ - Qualified webmaster resources (affiliate programs, web design, tips)

    ------
    Son

Similar Threads

  1. is number a prime number program
    By easy in forum Java Help
    Replies: 2
    Last Post: January 30th, 2004, 03:36 PM
  2. Replies: 23
    Last Post: January 2nd, 2004, 09:28 AM
  3. Replies: 12
    Last Post: December 6th, 2003, 06:31 PM
  4. Replies: 1
    Last Post: November 22nd, 2003, 03:02 PM

IMN logo majestic logo threadwatch logo seochat tools logo