\documentclass{article} \usepackage[a4paper]{geometry} \title{ P18 } \author{ Sam Wilson } \date{ 2020 November 4 (Wednesday), 1:57AM } \begin{document} \maketitle \tableofcontents Oh, maybe it's not possible! \url{https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/reference/faq.html#can-i-sort-by-a-function-for-example-order-by-rand-in-dql} \begin{quote} Can I sort by a function (for example ORDER BY RAND()) in DQL? No, it is not supported to sort by function in DQL. If you need this functionality you should either use a native-query or come up with another solution. As a side note: Sorting with ORDER BY RAND() is painfully slow starting with 1000 rows. \end{quote} \end{document}