incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Troy Kruthoff <tkruth...@blit.com>
Subject Re: _rev for random view???
Date Wed, 04 Feb 2009 21:19:40 GMT

Math.random() is avail, at least in 0.9.0a712819 and I hope it stays,  
most RDBMS have support for generating random numbers as well.  I  
realize this could be done @ the app level, but it's so much cleaner  
to me to have a view called random and be done with it.

-- troy



On Feb 4, 2009, at 12:47 PM, Chris Anderson wrote:

> On Wed, Feb 4, 2009 at 12:41 PM, Paul Davis <paul.joseph.davis@gmail.com 
> > wrote:
>> On Wed, Feb 4, 2009 at 3:18 PM, Chris Anderson <jchris@apache.org>  
>> wrote:
>>> On Wed, Feb 4, 2009 at 11:15 AM, Troy Kruthoff  
>>> <tkruthoff@blit.com> wrote:
>>>>
>>>> Anyone have thoughts on the best way to create a view of random  
>>>> documents?
>>>> I'm thinking a view with emit(doc._rev,null) would be sufficient  
>>>> for my
>>>> needs, but thought I'd ping the list for collective knowledge ;)
>>>>
>>>
>>> I'm not sure how _rev works for randomness.
>>>
>>> Math.random()
>>>
>>
>> Though you should *NEVER* use Math.random() in a view. Not sure if
>> it's even in the sandbox, but just in case.
>
> I don't think there's anything wrong with using it. If what you want
> is a random order.
>
> More efficient might be to take the seqid of the db, and generate a
> random # smaller than it. Then chose the docid based on the seq.
> however, that will bias for frequently updated docs.
>
> -- 
> Chris Anderson
> http://jchris.mfdz.com


Mime
View raw message