If you need performance, this should be it:

http://jsbin.com/uvuzi/edit

It sorts the rows using the "Fisher-Yates" shuffling algorithm.
Despite throwing elements around in an array, it's faster than the
pure mathematical solution because you don't need to filter out
duplicate random numbers. An even greater improvement can be made by
using the style.display property directly.

cheers,
- ricardo

On Mar 18, 4:20 pm, Scott Sauyet <li...@sauyet.com> wrote:
> Sean O wrote:
> > Nice job. I like the logic, and the fading out of unselected rows.
>
> > My solution was, admittedly, a quick one. It certainly wouldn't scale past
> > 1,000 rows or so -- especially with the majority # selected -- but if the
> > 10/50 number is firm, seemed to work OK.
>
> Yours is probably more efficient on average than mine, even at higher
> numbers, except in extreme cases.  The advantage of mine is in
> predictability.  It's going to loop through all the rows making one call
> to random() for each.
>
> Mine was actually a quick copy of something I recently had to do in my
> day job where this predictability was more important (to my boss) than
> average efficiency, and where the numbers were higher.  Although I coded
> this approach, I argued unsuccessfully for your approach, which is
> usually faster.
>
> In any case, either should work fine for the OP if the numbers are
> anything like the example given.
>
>    -- Scott

Reply via email to