public function findRandomBy(array $criteria, $limit)
    {
        $limit = intval($limit);
        if ($limit <= 1) {
            throw new \InvalidArgumentException('Please use `findRandomOneBy()` for single result.');
        }

        $queryBuilder = $this->getCollectionQueryBuilder();

        $this->applyCriteria($queryBuilder, $criteria);

        $query = $queryBuilder
            ->addSelect('RAND() as HIDDEN rand')
            ->orderBy('rand')
            ->setMaxResults($limit)
            ->getQuery()
        ;

        return $this->collectionResult($query);
    }
public function findRandomBy(array $criteria, $limit)
    {
        $limit = intval($limit);
        if ($limit <= 1) {
            throw new \InvalidArgumentException('Please use `findRandomOneBy()` for single result.');
        }

        $queryBuilder = $this->getCollectionQueryBuilder();

        $this->applyCriteria($queryBuilder, $criteria);

        $query = $queryBuilder
            ->addSelect('RAND() as HIDDEN rand')
            ->orderBy('rand')
            ->setMaxResults($limit)
            ->getQuery()
        ;

        return $this->collectionResult($query);
    }
public function findRandomBy ( array $ criteria , $ limit ) { $ limit = intval ( $ limit ) ; if ( $ limit <= 1 ) { throw new \ InvalidArgumentException ( 'Please use `findRandomOneBy()` for single result.' ) ; } $ queryBuilder = $ this -> getCollectionQueryBuilder ( ) ; $ this -> applyCriteria ( $ queryBuilder , $ criteria ) ; $ query = $ queryBuilder -> addSelect ( 'RAND() as HIDDEN rand' ) -> orderBy ( 'rand' ) -> setMaxResults ( $ limit ) -> getQuery ( ) ; return $ this -> collectionResult ( $ query ) ; }
Finds random resource by criteria and limit.

@param array $criteria
@param int   $limit

@return array|\Doctrine\ORM\Tools\Pagination\Paginator
Finds random resource by criteria and limit .