diff options
-rw-r--r-- | lib/album.lib.php | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/album.lib.php b/lib/album.lib.php index ef0c7124..6edfc932 100644 --- a/lib/album.lib.php +++ b/lib/album.lib.php @@ -95,14 +95,16 @@ function get_random_albums($count='') { $total = count($albums); - if ($total == '0') { return array(); } + if ($total < ($count+2)) { return array(); } for ($i=0; $i <= $count; $i++) { + $tries++; $record = rand(0,$total); - if (isset($results[$record]) || !$albums[$record]) { $i--; } + if (isset($results[$record]) || !$albums[$record]) { $i--; continue; } else { $results[$record] = $albums[$record]; } + if ($tries > 50) { return array(); } } // end for return $results; |