setFirstResult() based on 0.
Following your approach, you should use:
->setFirstResult(rand(0, $count - 1))->setMaxResults(1)->getSingleResult();
Source:
I agree that the documentation is unclear on this. However, we see that Doctrine \ DBAL \ Query \ QueryBuilder uses it like this:
->modifyLimitQuery($query, $this->maxResults, $this->firstResult);
SQL Doctrine\DBAL\Platforms\AbstractPlatform:
final public function modifyLimitQuery($query, $limit, $offset = null)
{
...
$query .= ' OFFSET ' . $offset;
OFFSET, 0 SQL, , setFirstResult() 0.