Here you go... an example of usage is put in the script.
<?php
function get_rands($min, $max, $amount)
{
$amount = (int) $amount;
$rands = array();
$rand = false;
for($i = 0; $i < $amount; ++$i)
{
while(!$rand || in_array($rand, $rands))
{
$rand = rand($min, $max);
}
$rands[] = $rand;
}
return $rands;
}
function rand_page($amount = 1)
{
$pages = array(
'http://www.google.com' => 'Google',
'http://www.ozzu.com' => 'Webmaster Resources',
'http://www.wedevoy.com' => 'Web Development',
'http://www.yahoo.com' => 'Yahoo',
'http://www.gmail.com' => 'Google Mail',
'http://www.ymail.com' => 'Yahoo Mail',
'http://www.ismywebsite.com' => 'Free cPanel web hosting',
'http://www.webfaction.com' => 'A good web host',
'http://www.phpbb.com' => 'phpBB Home Page',
$_SERVER['PHP_SELF'] => 'ME'
);
$i = 0;
foreach($pages as $link => $title)
{
$page[$i]['LINK'] = $link;
$page[$i]['TITLE'] = $title;
++$i;
}
$ids = get_rands(0, $i-1, $amount);
foreach($ids as $id)
{
$html .= "<a href=\"{$page[$id]['LINK']}\">{$page[$id]['TITLE']}</a><br />\n";
}
return $html;
}
// Test
echo rand_page(4);
?>
- <?php
- function get_rands($min, $max, $amount)
- {
- $amount = (int) $amount;
- $rands = array();
- $rand = false;
-
- for($i = 0; $i < $amount; ++$i)
- {
- while(!$rand || in_array($rand, $rands))
- {
- $rand = rand($min, $max);
- }
-
- $rands[] = $rand;
- }
-
- return $rands;
- }
-
- function rand_page($amount = 1)
- {
- $pages = array(
- 'http://www.google.com' => 'Google',
- 'http://www.ozzu.com' => 'Webmaster Resources',
- 'http://www.wedevoy.com' => 'Web Development',
- 'http://www.yahoo.com' => 'Yahoo',
- 'http://www.gmail.com' => 'Google Mail',
- 'http://www.ymail.com' => 'Yahoo Mail',
- 'http://www.ismywebsite.com' => 'Free cPanel web hosting',
- 'http://www.webfaction.com' => 'A good web host',
- 'http://www.phpbb.com' => 'phpBB Home Page',
- $_SERVER['PHP_SELF'] => 'ME'
- );
-
- $i = 0;
- foreach($pages as $link => $title)
- {
- $page[$i]['LINK'] = $link;
- $page[$i]['TITLE'] = $title;
- ++$i;
- }
-
- $ids = get_rands(0, $i-1, $amount);
-
- foreach($ids as $id)
- {
- $html .= "<a href=\"{$page[$id]['LINK']}\">{$page[$id]['TITLE']}</a><br />\n";
- }
-
- return $html;
- }
- // Test
- echo rand_page(4);
- ?>
Basically, what that '4' does in the Test part of the script is tell how many links it would have. To format the HTML, all you have to do is go to the following line:
$html .= "<a href=\"{$page[$id]['LINK']}\">{$page[$id]['TITLE']}</a><br />\n";
and manipulate the HTML (Leave the PHP along!

) and there you have it.
This is actually a quick re-write of the script I wrote for
mista-two-k
"Bring forth therefore fruits meet for repentance:" Matthew 3:8