从 Google App Engine 数据存储区获取随机记录? [英] Fetching a random record from the Google App Engine Datastore?

查看:24
本文介绍了从 Google App Engine 数据存储区获取随机记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据存储,模型中有大约 1,000,000 个实体.我想从中获取 10 个随机实体.

I have a datastore with around 1,000,000 entities in a model. I want to fetch 10 random entities from this.

我不知道该怎么做?有人可以帮忙吗?

I am not sure how to do this? can someone help?

推荐答案

为每个实体分配一个随机数并将其存储在实体中.然后查询随机数大于(或小于)某个其他随机数的十个记录.

Assign each entity a random number and store it in the entity. Then query for ten records whose random number is greater than (or less than) some other random number.

然而,这并不是完全随机的,因为具有附近随机数的实体往往会一起出现.如果您想打败它,请根据十个随机数进行十次查询,但这会降低效率.

This isn't totally random, however, since entities with nearby random numbers will tend to show up together. If you want to beat this, do ten queries based around ten random numbers, but this will be less efficient.

这篇关于从 Google App Engine 数据存储区获取随机记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆