Forum Moderators: coopster
<?php
$theVal=rand(0,2);
switch($theVal)
{
case 1:
include("include2.php");
break;
case 2:
include("include3.php");
break;
default:
include("include1.php");
break;
}
?>
to make sure it's fair you could record each selection to a database, then only call those that haven't already been shown.
This is contradictory ;) If you want 3 includes to be included 33.3% of the time, then each of them have the same probability of being chosen, therefore it's simply a random generator.
Following up on some of the previous examples, you can also use shuffle:
$files = [url=http://us3.php.net/manual/en/ref.array.php]array[/url]("file1.html","file2.html","file3.html");
[url=http://us3.php.net/manual/en/function.shuffle.php]shuffle[/url]($files);
include($files[0]);
Best of luck! :)
I could be wrong, but if it is random, there is a chance (in a given day), for example, that one will be 25% the other 35% and the third one 40%
That is if you are keeping track of how many show up of each throughout the day. The probabilty is truly 33.3% each time the page loads that any one will be selected.
If you are worried about users seeing the same content more than once before they view the others, there is a 33.3% chance that this will happen, but a more probable 66.6% chance that they will see something different.
Over time, I guess it will even out to 33.33% each.
Yes, it should eventually approach 33.33%...in theory ;)