I am trying to generate random articles from a category using the Wikipedia API sandbox.
But whenever the query is made articles were returned in alphabetical order rather than randomly. Also the same set of articles is returned each time. The number of articles retrieved each time is much lower than the total number of articles in the category. What is the bug in the query?
It does not make sense to use a list API with a generator. Most query APIs take a set of pagenames/ids as input, and this parameter can be replaced with a generator. List APIs take no such input so they won't be affected.
What actually happens is that the random API generates a single page (since its limit parameter defaults to 1) under the random
key; that page is properly random and changes with every request, but it isn't limited to the category (list APIs don't work that way). The return from the generator API (which is, of course, not random) is displayed under the pages
key, since any pages passed to the random API in the title
parameter are simply returned under that key.
What you could do is call Special:RandomInCategory (there is no API equivalent yet) and just retry until you get a main namespace page.