On 21/09/2010 18:27, Peter Braden wrote:
Hi,
Is there a good way to get a random document from a database.
Hmm, that depends upon what you mean by "good", and "random" and if you
want a repeatable result! I guess I'm asking what exactly are you trying
to do?
a) Pick a representative, and statistically defensible sample of size X
from a population of Y documents where each document has an equal
probability of being selected, and cannot be selected twice.
b) Take a sample of size 1 from a population of Y, X times (so a given
document could be taken more than once)?
c) Something similar to a or b where you don't know Y in advance?
d) Shuffle the documents?
I'm currently
using a view that does:
function(doc) {
emit(Math.random(), doc);
};
But as this isn't deterministic, I'm pretty sure it's wrong.
I don't follow your logic. The view will show all documents in a random
order. The fact that is is unrepeatable may make it useless for your
purposes, but it does not make the maths invalid, or the statistics wrong.
Regards
Ian