Index: acidfree.module
===================================================================
--- acidfree.module	(revision 536)
+++ acidfree.module	(working copy)
@@ -974,11 +974,14 @@
         $order = 'votes DESC';
         $join = 'INNER JOIN {node_counter} c on n.nid=c.nid ';
         $select = ', ABS(c.daycount*10 + c.totalcount) AS votes';
+    } else if ($order == 'RAND()') {
+        $order = 'rand DESC';
+        $select = ', RAND() as rand';
     }
     // FIXME: we should make this query use $acidfree_types
     if (count($albums) > 0) {
         $terms = implode(',', $albums);
-        $query = "SELECT n.nid FROM {node} n ".
+        $query = "SELECT n.nid $select FROM {node} n ".
             "INNER JOIN {term_node} t on n.nid=t.nid ".
             "WHERE n.type IN ('image', 'video') AND ".
             "t.tid IN ($terms) AND n.status=1 ".
@@ -1977,9 +1980,13 @@
     } else {
         $include_albums = "n.type <> 'acidfree' AND";
     }
+    if ($order == 'RAND()') {
+        $order = 'rand DESC';
+        $select = ', RAND() as rand';
+    }
     // Create count query. Drupal's pager function does not build the query properly
     $clauses = "FROM {node} n INNER JOIN {term_node} tn ON n.nid = tn.nid WHERE $include_albums tn.tid = %d AND n.status = 1";
-    $query = db_rewrite_sql("SELECT DISTINCT(n.nid), n.title, n.created " . $clauses.' ORDER BY '. $order);
+    $query = db_rewrite_sql("SELECT DISTINCT(n.nid), n.title, n.created $select " . $clauses.' ORDER BY '. $order);
     $count_query = db_rewrite_sql("SELECT COUNT(DISTINCT(n.nid)) " . $clauses);
     if ($limit == -1) {
         $kids = db_query($query, $tid);
