Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
(defn take-randnth [num coll]
(take num
(map first
(iterate (fn [[ret items]]
(let [idx (rand-int (count items))]
[(items idx)
(subvec (assoc items idx (items 0))
(vec coll)])))))
(defn lazy-shuffle [coll]
((fn shuffle [^clojure.lang.ITransientVector coll]
(let [c (count coll)]
(when-not (zero? c)
(let [n (rand-int c)]
(cons (get coll n)
(shuffle (.pop (assoc! coll n (get coll (dec c)))))))))))
(transient (vec coll))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment