function chooseRandomElement($array) { $rand_element = $array[rand(0, count($array) - 1)]; if (is_array($GLOBALS['CHOSEN_ITEMS']) && in_array($rand_element, $GLOBALS['CHOSEN_ITEMS']) && count($GLOBALS['CHOSEN_ITEMS']) < count($array)) { return PSUFiles::chooseRandomElement($array); } else { $GLOBALS['CHOSEN_ITEMS'][] = $rand_element; return $rand_element; } //end else }
/** * selects a random file from a given directory */ public function _random() { if ($this->type == 'image') { $files = PSUFiles::getImageArray($this->base_dir . $this->dir, 0, $this->depth); } else { $files = PSUFiles::getImageArray($this->base_dir . $this->dir, 0, $this->depth, array('txt', 'html')); } //end if $this->set(PSUFiles::chooseRandomElement($files)); }