I often find that I would like to show some elements of a page on random occasions. Ad placement, for example, is randomised on GOTXT.com.au.
Whatever your need is, there is a nice and easy way to pull it off, and that is with the following code:
<?php
$random = (rand(1,2)); // 50-50, picks a random number between 1 and 2.
echo “normal text” . ($random==1 ? “show 50% of time” : “other output” ) . “continue normal text”; //condensed if statement
?>
Obviously it might be easier to use regular if/elseif/else statements to control a wider range of random events.



