How can I split my traffic evenly?


I am conducting an A/B test of my website. I’d like to use sessions to select which version of the website each user will see. However, my concern is making sure approx equal amount of users view each version.

Any thoughts on best way to approach this?


insert a row into a database and see if the auto id it generates is even or odd.

Thanks for the reply, crmalibu

But I did find this, which helped lead me to a solution

rand() won’t ensure equal amounts of users are split between the two groups, but I guess I misinterpreted the significance of your question.

rand() should mathematically create a very good 50/50 ratio.

Yes, that’s what I’m looking for. I know I won’t get an exact 50/50 split, but if it’s 49/51 ish, then that is OK :wink:

should but in pratice i have not experienced so :slight_smile:

I know random generators in some other languages tend to be pretty good at 50/50, though this is PHP, so all bets are off.

Use mt_rand() instead, it passes the diehard tests for randomness.

$visits = 10000;
$t = array();
for($x=0; $x<$visits; $x++) {
  $t[] = rand(0,1);

not a lot of point in speculating. accuracy is higher with larger numbers.

Remember to set a cookie with what version the user is visiting as well, so that you can show them the same version if they visit back later.

rand() was not really “random” in the past, but I believe it was fixed, though dont quote me on that. By habit I am always using mt_rand() so I have not tested rand() the last few years.

See for visual comparisons.