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

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

问题描述

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

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

解决方案

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

然而,这并不完全是随机的,因为随机附近的实体数字会倾向于一起出现。如果你想打败这个,你可以做10个基于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天全站免登陆