Load $pNb elements ordered by RAND().

@param int $pNb
@return CollectionAbstract
190954
public function loadRandom($pNb = 1)
    {
        return $this->load(array(
            DbInterface::FILTER_LIMIT => $pNb,
            DbInterface::FILTER_ORDER => array(ItemInterface::IDFIELD => DbInterface::ORDER_RAND)
        ));
    }
67381
public static function first($collection = null, $n = null)
    {
        if ($n === 0) {
            return array();
        }
        if (is_null($n)) {
            return current(array_splice($collection, 0, 1, true));
        }
        return array_splice($collection, 0, $n, true);
    }
100963
public function load($collection = null)
    {

        $items = array();

        $list = DB::table($this->table);

        if ($collection !== null) {
            $list = $list->where('key', 'LIKE', $collection . '%');
        }

        $list = $list->pluck('value', 'key');


        // convert dotted list back to multidimensional array
        foreach ($list as $key => $value) {
            $value = json_decode($value);
            array_set($items, $key, $value);
        }

        return $items;
    }
53489
public function random()
    {
        $objReturn = null;

        $intIndex = rand(0, (count($this->collection) - 1));
        if (isset($this->collection[$intIndex])) {
            $objReturn = $this->collection[$intIndex];
        }

        return $objReturn;
    }
185555
public function setDbCollection(string $dbName, string $collectionName): \MongoCollection
    {
        return $this->mongoClient->selectDB($dbName)->selectCollection($collectionName);
    }
276515
public static function paginate($n, $current = 0, $chunk = null)
    {
        return static::query()->paginate($n, $current, $chunk);
    }
1167529
public function random($amount = 1)
    {
        if ($amount > ($count = $this->count())) {

            throw new InvalidArgumentException("You requested {$amount} items, but there are only {$count} items in the collection.");
        }

        $keys = array_rand($this->items, $amount);

        if (count(func_get_args()) == 0) {

            return $this->items[ $keys ];
        }

        $keys = !is_array($keys) ? [$keys] : $keys;

        return new static(array_intersect_key($this->items, array_flip($keys)));
    }
319106
protected function loadDefaultWith(EloquentCollection $collection): self
    {
        if ($collection->isEmpty()) {
            return $this;
        }

        $model = $collection->first();
        $reflection = new ReflectionClass($model);
        $withProperty = $reflection->getProperty('with');
        $withProperty->setAccessible(true);

        $with = array_filter((array) $withProperty->getValue($model), function ($relation) use ($model) {
            return ! $model->relationLoaded($relation);
        });

        if (! empty($with)) {
            $collection->load($with);
        }

        return $this;
    }
1193426
public function getCollections($databaseName = null) {
		$database = $this->getDatabase($databaseName);

		if ($this->_profilerEnabled) {
			$event = $this->getProfiler()->startRead('Collections list');
		}

		$collections = $database->getCollectionNames();

		if ($this->_profilerEnabled) {
			$event->stopSuccess();
		}

		return $collections;
	}
17047
public function setCollection($collection)
    {
        $this->collection = $collection;

        $this->collection->setCurPage($this->getCurrentPage());

        // we need to set pagination only if passed value integer and more that 0
        $limit = (int)$this->getLimit();
        if ($limit) {
            $this->collection->setPageSize($limit);
        }
        if ($this->getCurrentOrder()) {
            $this->collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
        }

        return $this;
    }
689589
public function loadItemWithPositionData(Collection $collection, int $position): array
    {
        $query = $this->getItemSelectQuery();
        $query->where(
            $query->expr()->andX(
                $query->expr()->eq('collection_id', ':collection_id'),
                $query->expr()->eq('position', ':position')
            )
        )
        ->setParameter('collection_id', $collection->id, Type::INTEGER)
        ->setParameter('position', $position, Type::INTEGER);

        $this->applyStatusCondition($query, $collection->status);

        return $query->execute()->fetchAll(PDO::FETCH_ASSOC);
    }
953017
public function loadByShopgateOrderNumber($number)
    {
        $order = $this->_getResource()->getByOrderNumber($number);
        if (!empty($order)) {
            $this->setData($order);
        }

        return $this;
    }
116188
public function rand($num = 1)
    {
        try {
            $arr = array_rand($this->val(), $num);
        } catch (\ErrorException $e) {
            throw new ArrayObjectException($e->getMessage());
        }

        if (!$this->isArray($arr)) {
            $arr = [$arr];
        }

        return new ArrayObject($arr);
    }
199849
public function last($collection=null, $n=null) {
    list($collection, $n) = self::_wrapArgs(func_get_args(), 2);
    $collection = self::_collection($collection);
    
    if($n === 0) $result = array();
    elseif($n === 1 || is_null($n)) $result = array_pop($collection);
    else {
      $__ = new self;
      $result = $__->rest($collection, -$n);
    }
    
    return self::_wrap($result);
  }
757231
public static function load($groupname)
    {
        $groups = self::groups();

        $content = $groups[$groupname] ?? [];
        $content += ['groupname' => $groupname];

        $blueprints = new Blueprints();
        $blueprint = $blueprints->get('user/group');

        return new Group($content, $blueprint);
    }
576791
public function loadBlockCollectionIds(array $blockIds, ?int $status = null): array
    {
        $query = $this->connection->createQueryBuilder();
        $query->select('DISTINCT bc.collection_id')
            ->from('ngbm_block_collection', 'bc')
            ->where(
                $query->expr()->in('bc.block_id', [':block_id'])
            )
            ->setParameter('block_id', $blockIds, Connection::PARAM_INT_ARRAY);

        if ($status !== null) {
            $this->applyStatusCondition($query, $status, 'bc.block_status', 'block_status');
        }

        $result = $query->execute()->fetchAll(PDO::FETCH_ASSOC);

        return array_column($result, 'collection_id');
    }
486199
public function first($sql = null)
    {
        $obj = $this->getFirst($sql);

        if ($obj && $this->getWith()) {
            $collection = new Collection();
            $collection->add($obj);

            $this->resolveRelations($collection);

            return $collection->first();
        }

        return $obj;
    }