public static function randLocation($items = -1) { $rawLocations = PkTestGenerator::randData(static::$ca_cities, $items); if ($items === -1) return static::locationAssoc($rawLocations); $assocLocs = []; foreach ($rawLocations as $rawLocation) { $assocLocs[] = static::locationAssoc($rawLocation); } return $assocLocs; }
/** * Return a random instance, or array (collection) of random instances * @param integer $num: If -1 (default), return single instance. * if ($num >= 0) return array/collection of $num instances * @param array $params - Can be used by subclasses to filter * @return instance|array instances - */ public static function getRandomInstances($num = -1, $params = []) { if ($num === 0) { return []; } $instances = static::all(); $numinst = count($instances); if (!$numinst) { if ($num === -1) { return null; } return []; } return PkTestGenerator::getRandomData($instances, $num); }