Highly non-optimal solution: have a cron job assign new random numbers
to your entities often enough to simulate randomness.  Even just re-
assigning numbers to entities that have been previously selected might
work.  This involves a lot more CPU as you'd be doing writes, but
shifts the work from request time to a background process so your
users don't see the added latency for doing N queries.

Another possible solution would be to fetch keys only for X*N entities
(where greater X's produce more apparent randomness) then choose N of
those keys to actually fetch entities.

On Jul 9, 12:33 pm, aloo <aleem.maw...@gmail.com> wrote:
> Hi all,
>
> I'm trying to write a GQL query that returns N random records of a
> specific kind. My current implementation works but requires N calls to
> the datastore. I'd like to make it 1 call to the datastore if
> possible.
>
> I currently assign a random number to every kind that I put into the
> datastore. When I query for a random record I generate another random
> number and query for records > rand ORDER BY asc LIMIT 1.
>
> This works, however, it only returns 1 record so I need to do N
> queries. Any ideas on how to make this one query? Thanks.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to