PostgreSQL RANDOM() function for Doctrine ORM
$ composer require qbbr/pgsql-doctrine-random-function
# app/config/config.yml
doctrine:
orm:
# ...
dql:
numeric_functions:
Random: Qbbr\PgsqlDoctrineRandomFunction\DQL\RandomFunction
$em = $this->getDoctrine()->getManager();
$result = $em->createQueryBuilder()
->select('e')
->from('AppBundle:Entity', 'e')
->orderBy('RANDOM()')
->setMaxResults(10)
->getQuery()
->getResult();