Thread: Lycia
View Single Post
  #13  
Old 03-18-2001, 04:36 PM
galen galen is offline
Professional God
Join Date: Mar 2001
Location: Colorado, USA
Posts: 925
galen is on a distinguished road
Post Random sig script optomization

Use this one if you don't plan to keep adding more and more sigs.
NPC Code:
<?php 
header("content-type: image/gif");
srand((double)microtime()*10000000);
$randomtopic = rand(1,5);
switch ($randomtopic) {
2: include("avatar2.gif");
3: include("avatar3.gif");
4: include("avatar4.gif");
5: include("avatar5.gif");
default: include("avatar1.gif");
}
?>


Use this one if you'd going to add tons of them. This code removes the need to change the code each time you add more.
NPC Code:
<?php 
header("content-type: image/gif");
srand((double)microtime()*10000000);
$i=1;
$handle=opendir("sigs");
while ($file = readdir($handle)) {
if ($file != "." && $file != "..") {
$dirlist[$i] = $file;
$i++;
}
}
closedir($handle);
$randomtopic = rand(1,sizeof($dirlist));
include("sigs/".$dirlist[$randomtopic]);
?>

__________________
Galen S. Kant
galen "at" terraweb.net
Reply With Quote