=> (defn lazy-shuffle [v]
(lazy-seq
(if (seq v)
(let [idx (rand-int (count v))]
(cons (nth v idx)
(lazy-shuffle (pop (assoc v idx (peek v)
=> (take 10 (lazy-shuffle (vec (range 100
(77 63 37 99 81 73 25 85 35 10)
On Fri, Aug 23, 2013 at 1
(letfn [(vec-throw-out [v i]
(pop (assoc v i (get v (dec (count v))]
(defn lazy-shuffle [v]
(if (seq v)
(let [idx (rand-int (count v))]
(cons
(get v idx)
(lazy-seq
(lazy-shuffle
(vec-throw-out v idx
(let [s (range 100)
v (vec s)]
(ti
On Jul 11, 5:44 am, Sunil S Nandihalli
wrote:
> Hello everybody,
> I think a lazy version of shuffle would be a good addtion to the core. I
> tried googling for one and
> foundhttp://ytakenaka.blogspot.com/2011/05/lazy-shuffle-clojure.htmlwhich was
> infact slower than original
On Mon, Jul 11, 2011 at 1:13 PM, Alan Malloy wrote:
> If the sequence is already realized, or is cheap, and you want only a
> very small random subset of it, you can do better than shuffling the
> whole thing. Fliebel and I played around with several solutions to
> this, some time ago. I can't fin
s and benchmarking data are at https://gist.github.com/805747
if you want to try it out.
On Jul 11, 3:57 am, Tassilo Horn wrote:
> Sunil S Nandihalli writes:
>
> Hi Sunil,
>
> > I think a lazy version of shuffle would be a good addtion to the
> > core. I tried googl
One thing to keep in mind when shuffling is that, by default,
if the input sequence is large enough then most permutations
can never be generated by shuffle. This follows naturally from
the Dirichlet's pigeonhole principle: there are only 2^64 possible
seeds (states of the RNG), but (factorial (cou
Sunil S Nandihalli writes:
Hi Sunil,
> yea true, the full sequence has to be realized before it is shuffled
> .. but however the thing is that I am only interested in the first
> couple of elements of the shuffled sequence.
Well, in that case, you can use the standard shuffle, right? For
examp
have
got better performance if I had passed in a "Counted" collection which was
not true in my case..
Sunil.
On Mon, Jul 11, 2011 at 4:27 PM, Tassilo Horn wrote:
> Sunil S Nandihalli writes:
>
> Hi Sunil,
>
> > I think a lazy version of shuffle would be a good
Sunil S Nandihalli writes:
Hi Sunil,
> I think a lazy version of shuffle would be a good addtion to the
> core. I tried googling for one and found
> http://ytakenaka.blogspot.com/2011/05/lazy-shuffle-clojure.html which
> was infact slower than original shuffle and was unable to rep
Hello everybody,
I think a lazy version of shuffle would be a good addtion to the core. I
tried googling for one and found
http://ytakenaka.blogspot.com/2011/05/lazy-shuffle-clojure.html which was
infact slower than original shuffle and was unable to reproduce the
performance claims made there in
10 matches
Mail list logo