Check out this script.
for ($index = 1; $index <= 1000; $index++) {
$rand[] = rand(1,2);
}
dump(count(array_filter($rand, function ($value) { return $value == 1; })));
dump(count(array_filter($rand, function ($value) { return $value == 2; })));
$rand = [];
for ($index = 1; $index <= 1000; $index++) {
if($index % 2 == 0){
array_push($rand, 2);
} else {
array_push($rand, 1);
}
}
dump(count(array_filter($rand, function ($value) { return $value == 1; })));
dump(count(array_filter($rand, function ($value) { return $value == 2; })));
The first for loop works as you have your script above and the distribution is not equal - it can be 400, 600. The second one the distribution is equal - 500,500. So to answer your question - if you are to distribute the traffic evenly - you are better of not using a randomn number to make the decision.
I would rather you have a variable that you increment when sending traffic to google and decrement when sending it to yahoo - then you always check this value before making the decision to route traffic.