Do you now what your keys range, either id (will be easier) or names
(harder)
Also it do you have an idea about the distribution of keys over the
range? An even distribution would be better.

Based on id's for keys you could

choose a random number in the known range (or ranges),
construct a key, do a query on the key >=  or <= and get the first
entity found matching.

This sort of approach isn't going to be very random if you key
distribution is clumped.  Any random number falling into an empty
range of keys
will always give you the first or last key of a clump. If you have
clumps of id's then you could also use a random offset when you do the
fetch.

A better alternative if you you don't have lots of entities would be
to do a keys only query, fetch all the keys
and then perform a random choice from the list of keys. Then fetch the
entity for the chosen key.

The approach all depends on how random you want your choice to be, key
distribution and number of entities to choose from

T



On Sep 25, 10:18 am, james_027 <[email protected]> wrote:
> Hi All,
>
> Any tips on how to get a random record?
>
> Thanks,
> James

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to