I'm adding in my website an Ads revenue sharing system, I built everything, for the ads sharing logic
$random_number = mt_rand(1,10);
if (($random_number >= 1) && ($random_number < 8)) { //gets 1-7 for 70%
$ads = "USER-ADS";
}
if (($random_number >= 8) && ($random_number < 11)) { //gets 8,9, and 10 for 30%
$ads = "ADMIN-ADS";
}
Is this logic is valid?
I want to show the user Ads to 70% of the pageviews, and show my ads for the remaining 30%
The logic looks good. You could use
if ($random_number < 8) {
$ads = 'USER-ADS';
} elseif ($random_number >= 8) {
$ads = 'ADMIN-ADS';
}
as it's a bit more compact and (trivially) faster.