On Sep 26, 2:12 pm, Paul Richards wrote:
> On Sep 26, 2:12 pm, Paul Richards wrote:
>
> > Hi,
> > How can I efficiently pick a random element from a sorted-set?
>
> I've come up with a bit of a hack, which relies on me not caring about
> non-uniform distributions. If I create a custom comparator
On Monday, September 26, 2011 2:58:59 PM UTC-6, Paul Richards wrote:
>
> This will replace an O(n) call to "nth" with an O(n) call to copy into
> a vector, so still leaving me with O(n).
>
Oops, right :) If you're getting random elements out of the same sorted set
multiple times, then it might
On Sep 26, 6:04 pm, Benny Tsai wrote:
> The reason that (rand-nth (seq (sorted-set 1 2 3))) performs badly on large
> sets is probably because nth is O(n) on sequences. nth is much much faster
> on vectors, so I would suggest trying out (rand-nth (vec (sorted-set 1 2
> 3))) and see if that works
On Sep 26, 6:13 pm, Jeremy Heiler wrote:
> On Mon, Sep 26, 2011 at 9:12 AM, Paul Richards
> wrote:
> > Hi,
> > How can I efficiently pick a random element from a sorted-set?
>
> > If I try rand-nth I get this:
> > user=> (rand-nth (sorted-set 1 2 3))
> > java.lang.UnsupportedOperationException:
On Sep 26, 2:12 pm, Paul Richards wrote:
> Hi,
> How can I efficiently pick a random element from a sorted-set?
>
I've come up with a bit of a hack, which relies on me not caring about
non-uniform distributions. If I create a custom comparator with a
"random" backdoor, I can select random elemen
On Mon, Sep 26, 2011 at 9:12 AM, Paul Richards wrote:
> Hi,
> How can I efficiently pick a random element from a sorted-set?
>
> If I try rand-nth I get this:
> user=> (rand-nth (sorted-set 1 2 3))
> java.lang.UnsupportedOperationException: nth not supported on this
> type: PersistentTreeSet (NO_S
The reason that (rand-nth (seq (sorted-set 1 2 3))) performs badly on large
sets is probably because nth is O(n) on sequences. nth is much much faster
on vectors, so I would suggest trying out (rand-nth (vec (sorted-set 1 2
3))) and see if that works for your application.
--
You received this
On Sep 26, 2011, at 8:12 AM, Paul Richards wrote:
> How can I efficiently pick a random element from a sorted-set?
If your sorted set is densely packed (if most possible values do appear in the
set), then you could just pick a random value, see if it's in the set, and
repeat until you find a ma
Hi,
How can I efficiently pick a random element from a sorted-set?
If I try rand-nth I get this:
user=> (rand-nth (sorted-set 1 2 3))
java.lang.UnsupportedOperationException: nth not supported on this
type: PersistentTreeSet (NO_SOURCE_FILE:0)
I can get this expression to work if I naively apply