function weightedRandom($resource, $field, $show) { $type = $this->getDocVarType($field); if ($type == "unknown") { return $resource; // handle vad field passed } $random = new random(); foreach ($resource as $document) { $doc = $document; $random->add($doc, abs(intval($document[$field]))); } $resource = $random->select_weighted_unique($show); shuffle($resource); return $resource; }