Code: Select all
<?php
function dodosrandgen() {
// set number of links you want to show at once
$show_link = 5;
// separate the links by, i.e. comma would be ",";
$separator = " ";
// Add links
// Please make sure you number entries CORRECTLY
// Look at the example for reference!
// DO NOT erase the priority part, leave all
// to 1 if you don't want them to have different
// priorities!
$links[0][link] = "havregyn</br>";
$links[0][priority] = 25;
$links[1][link] = "helse</br>";
$links[1][priority] = 1;
$links[2][link] = "oatmeal</br>";
$links[2][priority] = 1;
$links[3][link] = "eggknock</br>";
$links[3][priority] = 1;
$links[4][link] = "";
$links[4][priority] = 15;
$links[5][link] = "";
$links[5][priority] = 15;
$links[6][link] = "green beans</br>";
$links[6][priority] = 60;
$links[7][link] = "bananasplit</br>";
$links[7][priority] = 40;
// HERE COMES THE BODY
if($links) {
for($i = -1; $i < count($links); $i++) {
for($j = 0; $j < $links[$i][priority]; $j++) {
$newlinksindex = count($newlinks) + 1;
$newlinks[$newlinksindex] = $links[$i][link];
}
}
} // end of if link exist
// debug
if($show_link >= count($newlinks))
$show_link = count($newlinks);
$showarray[0] = "";
$showindex = 0;
// Select a random element from the new array
do {
$randindex = rand(0, count($newlinks));
if(!in_array($newlinks[$randindex], $showarray) && $newlinks[$randindex] != "") {
$showarray[$showindex] = $newlinks[$randindex];
//print_r($showarray);
$showindex++;
}
}while(count($showarray) <= $show_link);
// finally print out
for($i = 0; $i < $show_link; $i++ ) {
if($show_link == 1 || (($i + 1) == $show_link))
print $showarray[$i];
else
print $showarray[$i].$separator;
}
//print_r($ranarray);
//print_r($links);
//print_r($newlinks);
} // end of the dodosrandgen function
?>