Printed May 24, 2013 from B&T's Tips & Scripts
http://tips-scripts.com
Random/weighted banners (images), quotes & more
This script will display banners (with or without links), quotes, or anything else you want to randomly select with each individual page load. The item will be randomly selected, but the frequency of selection can be weighted based on a value you specify. For example, giving an item a weight of 2 will cause that item to be selected twice as often as an item with a weight of 1. Use only integers 1 or greater for weight values.
<?php
$externalFile = "N"; // Y means the item array contains file names
// add to the weight and item arrays below
$weight[0] = 1; $item[0] = "<a href='link0.htm'><img src='image0.gif' alt='' /></a>";
$weight[1] = 1; $item[1] = "<a href='link1.htm'><img src='image1.gif' alt='' /></a>";
$weight[2] = 1; $item[2] = "<a href='link2.htm'><img src='image2.gif' alt='' /></a>";
// end of arrays
for ( $a=0; $a<count($weight); $a++ )
for ( $b=1; $b<=$weight[$a]; $b++ ) $pick[] = $a;
$selected = $item[$pick[rand(0,count($pick)-1)]];
if ($externalFile == "Y") $selected = file_get_contents($selected);
echo $selected;
?>