Re: a lazy version of shuffle.

2013-08-23 Thread Christophe Grand
=> (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

Re: a lazy version of shuffle.

2013-08-23 Thread NeedMoreDesu
(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

Re: a lazy version of shuffle.

2011-07-12 Thread Brian Goslinga
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

Re: a lazy version of shuffle.

2011-07-11 Thread Ken Wesson
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

Re: a lazy version of shuffle.

2011-07-11 Thread Alan Malloy
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

Odp: Re: a lazy version of shuffle.

2011-07-11 Thread Daniel Janus
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

Re: a lazy version of shuffle.

2011-07-11 Thread Tassilo Horn
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

Re: a lazy version of shuffle.

2011-07-11 Thread Sunil S Nandihalli
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

Re: a lazy version of shuffle.

2011-07-11 Thread Tassilo Horn
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

a lazy version of shuffle.

2011-07-11 Thread Sunil S Nandihalli
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