On Apr 1, 3:06 pm, Andy Tinkham <[email protected]> wrote:
> Once I get a sequel dataset built, I'd like to pick one element at random 
> from it. What's the best way to do this? Retrieve an array of all the key 
> values and pick one randomly and then filter the entire dataset on that 
> value? Use the limit function with a limit of 1 and an offset of a random 
> number from 0 to the dataset count - 1? Some other way that I'm not thinking 
> of?

There's rarely a database independent way of doing
so.  .order{rand{}}.first will work for some databases, I think others
use random instead of rand.  And that way in general is slow for large
datasets.  If you know the number of records, .limit(1, rand * num)
will also work (as you suggest), but can be slow as well.  Fast ways
are definitely going to be database if not dataset dependent.

Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to