Return-Path: Delivered-To: apmail-couchdb-user-archive@www.apache.org Received: (qmail 24075 invoked from network); 23 Sep 2010 20:33:19 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 23 Sep 2010 20:33:19 -0000 Received: (qmail 11898 invoked by uid 500); 23 Sep 2010 20:33:18 -0000 Delivered-To: apmail-couchdb-user-archive@couchdb.apache.org Received: (qmail 11825 invoked by uid 500); 23 Sep 2010 20:33:17 -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 11817 invoked by uid 99); 23 Sep 2010 20:33:17 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Sep 2010 20:33:17 +0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests=FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS,T_TO_NO_BRKTS_FREEMAIL X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: local policy) Received: from [212.27.42.3] (HELO smtp3-g21.free.fr) (212.27.42.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 23 Sep 2010 20:33:12 +0000 Received: from zimbra5-e1.priv.proxad.net (unknown [172.20.243.155]) by smtp3-g21.free.fr (Postfix) with ESMTP id 4C9ACA616C for ; Thu, 23 Sep 2010 22:32:45 +0200 (CEST) Date: Thu, 23 Sep 2010 22:32:43 +0200 (CEST) From: mickael.bailly@free.fr To: user@couchdb.apache.org Message-ID: <2011309974.6180781285273963810.JavaMail.root@zimbra5-e1.priv.proxad.net> In-Reply-To: Subject: Re: Random Document MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [88.161.108.151] X-Mailer: Zimbra 5.0 (ZimbraWebClient - SAF3 (Linux)/5.0.15_GA_2815.UBUNTU8_64) X-Authenticated-User: mickael.bailly@free.fr Hello, please see this thread http://couchdb.markmail.org/search/selecting+a+rando= m+subset+of+a+view for good ideas to implement randomness. I opened a Jira = ticket to have some random API option, but for now it's still only a wish. Mickael ----- Mail Original ----- De: "Aaron Miller" =C3=80: user@couchdb.apache.org Envoy=C3=A9: Jeudi 23 Septembre 2010 09h10:43 GMT +01:00 Amsterdam / Berlin= / Berne / Rome / Stockholm / Vienne Objet: Re: Random Document Use a hash, like sha1 to transform the non-uniform id distribution to a random distribution deterministially. emit(sha1(doc._id)). (plenty of JS SHA1 hash libs around) Then to pull a random value out, query the view with startkey=3Dsha1(random number gen'd at query time) and limit=3D1. On Tue, Sep 21, 2010 at 10:27 AM, Peter Braden < PeterBraden@peterbraden.co.uk> wrote: > Hi, > > Is there a good way to get a random document from a database. I'm current= ly > 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've done a bit of googling, and haven't found anything. > > Cheers, > > Peter > > > > -- > Peter Braden > > >