Page 1 of 1

Selecting between two IDs using percentages...

Posted: Fri Jun 29, 2007 2:55 pm
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... :(

Posted: Fri Jun 29, 2007 3:15 pm
by Gente

Code: Select all

function GetID()
{
  if (rand(0, 100) < 70)
  {
    return 1;
  }
  return 2;
}

Posted: Fri Jun 29, 2007 3:17 pm
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.