Fix random generator handling of no results

If a random generator returns no results, QueryGenerator.__iter__
loops forever.

This was found when running site_tests on test.wikidata.org;
resulting in a travis build breakage in testRandompages

Change-Id: I5e6fde7505a1a2995c58d309233dcb185a69d74a
Merge "Fix random generator handling of no results"