Skip to content

Instantly share code, notes, and snippets.

@kliph
Created December 3, 2014 03:15
Show Gist options
  • Save kliph/e85046d788362c1ce0bb to your computer and use it in GitHub Desktop.
Save kliph/e85046d788362c1ce0bb to your computer and use it in GitHub Desktop.
Sampling without replacement in Clojure
(defn sample-without-replacement [coll]
"Returns a tuple in which the first value is the sample and the
second is a collection of the left over values. Does not preserve
the order of the input collection."
(let [shuffled (shuffle coll)
sample (last shuffled)
rest (pop shuffled)]
[sample rest]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment