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 find the whole thing, but some
interesting examples 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 <tass...@member.fsf.org> wrote:
> Sunil S Nandihalli <sunil.nandiha...@gmail.com> 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.htmlwhich
> > was infact slower than original shuffle and was unable to reproduce
> > the performance claims made there in.
>
> I think there is no way to implement a "good" lazy version of shuffle.
> Correct shuffling, i.e., the result should be a real pseudo-random
> permutation of all elements, can only be defined on finite seqs anyway.
> And there, one has to realize the given seq.  In the code you cite,
> there's
>
>   (defn lazy-shuffle [lst fetch-len]
>     (let [len (count lst)
>               ^^^^^^^^^^^
>
> which does exactly that.  So here only the cheap creation of the
> shuffled seq is lazy, but the possibly expensive calculation of the
> given seq is (and has to be done) directly.
>
> Bye,
> Tassilo

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to