Skip to content

Instantly share code, notes, and snippets.

@pandeiro
Forked from amalloy/take-randnth.clj
Created November 3, 2011 17:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pandeiro/1337074 to your computer and use it in GitHub Desktop.
Save pandeiro/1337074 to your computer and use it in GitHub Desktop.
(defn take-randnth [num coll]
(take num
(rest
(map first
(iterate (fn [[ret items]]
(let [idx (rand-int (count items))]
[(items idx)
(subvec (assoc items idx (items 0))
1)]))
[nil
(vec coll)])))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment