Sometimes we need to randomly acquire data records (entities), such as the implementation of "random articles" in a blog program.
At present, GAE does not have APIs to directly access random entities, to achieve such a demand we can only find a way to do it:-)
The issue was also mentioned on StackOverflow, as summarized below: Generate and store a random number on your entities as for you create them, then pick a random Number and look through (via a query) for the "closet record" (s) to it. Implement some mechanism to ensure your entity IDs are "densely" populated, then fetch within the known range using keys. Periodically generate random lists of the entities and return entities from those lists. This could take the form of a stack that entities are popped off, or as actual lists that are.
At present, B3log Solo in the processing of "random reading" on the method is one, that is, in each article entity to add a property to save 0-1 of the random floating-point number.
Generates a random article 0-1 of the random number (mid) as a query condition, with this query condition as the boundary (0 <= mid <=1) to filter the entity saved random value properties.
This method can basically achieve a random effect, in order to make the random effect more dynamic, we can consider to update the article entity random floating-point values frequently: when accessing an article (that is, updating the article's random floating-point values when the article is browsed) Background timed task (gets a certain number of random articles and then updates their random floating-point values) when the user makes a fuss update
Plus the above treatment, the random effect is better:-)
This article is to use the B3log Solo from the minimalist design of the art to synchronize the publication of the original address: http://88250.b3log.org/get-gae-random-entities.html