Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 85450 invoked from network); 21 Sep 2010 19:26:28 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 21 Sep 2010 19:26:28 -0000 Received: (qmail 788 invoked by uid 500); 21 Sep 2010 19:26:26 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 721 invoked by uid 500); 21 Sep 2010 19:26:26 -0000 Mailing-List: contact user-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: user@couchdb.apache.org Delivered-To: mailing list user@couchdb.apache.org Received: (qmail 713 invoked by uid 99); 21 Sep 2010 19:26:26 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 21 Sep 2010 19:26:26 +0000 X-ASF-Spam-Status: No, hits=0.7 required=10.0 tests=RCVD_IN_DNSWL_NONE,SPF_NEUTRAL X-Spam-Check-By: apache.org Received-SPF: neutral (nike.apache.org: local policy) Received: from [81.103.221.48] (HELO mtaout02-winn.ispmail.ntl.com) (81.103.221.48) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 21 Sep 2010 19:26:16 +0000 Received: from aamtaout03-winn.ispmail.ntl.com ([81.103.221.35]) by mtaout02-winn.ispmail.ntl.com (InterMail vM.7.08.04.00 201-2186-134-20080326) with ESMTP id <20100921192555.MBVD3192.mtaout02-winn.ispmail.ntl.com@aamtaout03-winn.ispmail.ntl.com> for ; Tue, 21 Sep 2010 20:25:55 +0100 Received: from jupiter.ianhobson.co.uk ([86.12.69.89]) by aamtaout03-winn.ispmail.ntl.com (InterMail vG.2.02.00.01 201-2161-120-102-20060912) with ESMTP id <20100921192555.HHKH1807.aamtaout03-winn.ispmail.ntl.com@jupiter.ianhobson.co.uk> for ; Tue, 21 Sep 2010 20:25:55 +0100 Received: (qmail 25722 invoked by uid 453); 21 Sep 2010 19:25:49 -0000 X-Virus-Checked: Checked by ClamAV on ianhobson.co.uk Received: from almostbritish.leda.hcs (HELO [192.168.0.12]) (192.168.0.12) by ianhobson.co.uk (qpsmtpd/0.83) with ESMTP; Tue, 21 Sep 2010 20:25:49 +0100 Message-ID: <4C9906BA.6090205@ianhobson.co.uk> Date: Tue, 21 Sep 2010 20:25:46 +0100 From: Ian Hobson User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2.9) Gecko/20100915 Lightning/1.0b2 Mnenhy/0.8.3 Thunderbird/3.1.4 MIME-Version: 1.0 To: user@couchdb.apache.org Subject: Re: Random Document References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Cloudmark-Analysis: v=1.1 cv=DhNl2YeytwJssBBGe49HJX82LNDFEEVkpVB34RXKaPo= c=1 sm=0 a=8nJEP1OIZ-IA:10 a=0oEcD1VESjgQr2waWbcA:9 a=rt0GjBFM3Qi5vR2lWGOIsimwL3UA:4 a=wPNLvfGTeEIA:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117 X-Virus-Checked: Checked by ClamAV on apache.org 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