Selecting between two IDs using percentages...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Arok01
Forum Newbie
Posts: 1
Joined: Fri Jun 29, 2007 2:51 pm

Selecting between two IDs using percentages...

Post by Arok01 »

Okay, my title might not be clear enough...

What I need is to know how to program this in PHP.

I have two accounts (say ID1 and ID2) and I need to display ID1 70% of the time while ID2 is displayed 30% of the time...

How can I tell where I am and who I should display next ?

This is really urgent and a prompt response would be greatly appreciated... :(
User avatar
Gente
Forum Contributor
Posts: 252
Joined: Wed Jun 13, 2007 9:43 am
Location: Ukraine, Kharkov
Contact:

Post by Gente »

Code: Select all

function GetID()
{
  if (rand(0, 100) < 70)
  {
    return 1;
  }
  return 2;
}
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Just so you know, the function above will only be "accurate" when applying the law of large numbers. If you truly need to it to 70/30 then you should look into a database solution whereby you can track which div has been shown x amount of times in contrast to the other div.
Post Reply