I came with this, maybe it will help I tested it a bunch and it never seemed to put in any duplicates:
$filearray = array();
$dir = dir(".");
while($file = $dir->read()) {
if (($file != ".") && ($file != "..") && (!is_dir($file))) {
$files[] = $file;
}
}
$dir->close();
function add_to_array($element) {
global $filearray;
$filearray[] = $element;
}
function check_array($check) {
global $filearray;
if(!in_array($check, $filearray)) {
return true;
}
else {
return false;
}
}
function get_rand($rand = "") {
global $files;
srand((double)microtime()*1000000);
$randval = rand (0,(count($files)-1));
return $randval;
}
while (count($filearray) < 5) {
$rand = get_rand();
if (check_array($files[$rand])) {
$filearray[] = $files[$rand];
}
}
while (list($key,$val) = each($filearray)) {
print $val."<br>";
}