title: Random order for ArrayCollection in Symfony 3
body: <p>Here's part of my <code>Question</code> Entity:</p>
  
  <pre><code>   /**
       * @ORM\OneToMany(targetEntity="Answer", mappedBy="question", cascade={"all"})
       */
      private $options;
  </code></pre>
  
  <p>and here's part of the <code>Answer</code> Entity:</p>
  
  <pre><code>   /**
       * @ORM\Column(name="answer", type="text")
       */
      private $option;
  </code></pre>
  
  <p>Here's the Repository that gets random questions:</p>
  
  <pre><code>public function findQuestionsForQuiz($quantity = 0)
      {
          // get the lowest id
          $lowestId = $this-&gt;createQueryBuilder('q')
              -&gt;select('q.id')
              -&gt;orderBy('q.id', 'ASC')
              -&gt;setMaxResults(1)
              -&gt;getQuery()
              -&gt;getSingleScalarResult()
          ;
  
          // get the total number of questions
          $totalRows = $this-&gt;createQueryBuilder('q')
              -&gt;select('COUNT(q.id)')
              -&gt;getQuery()
              -&gt;getSingleScalarResult()
          ;
          $randomQuestionIds = $this-&gt;uniqueRandomNumbersWithinRange($lowestId, $totalRows+$lowestId, $quantity);
  
          $qb = $this-&gt;createQueryBuilder('q')
              -&gt;where('q.id IN(:ids)')
              -&gt;setParameter('ids', $randomQuestionIds)
              -&gt;getQuery()
          ;
  
          return $qb-&gt;getResult();
      }
  </code></pre>
  
  <p>While this is working fine, I've been trying to get the Answers to be sorted randomly and am not quite sure how to do this.</p>