Created
May 9, 2016 20:56
-
-
Save patham9/789a459c1ba1113de7864dc0f337dbdc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn use-counter-increment [] | |
(do | |
(dosync (ref-set use-counter (inc (deref use-counter)))) | |
@use-counter)) | |
;Adjusted shuffle given a seed, "shuffle-with-seed", from sloth: | |
;http://stackoverflow.com/questions/24553212/how-to-take-n-random-items-from-a-collection-in-clojure | |
;(since we don't want non-deterministic testcases) | |
(defn shuffle-random | |
"Return a random permutation of coll with a seed" | |
[coll] | |
(do | |
(use-counter-increment) | |
(let [seed (deref use-counter) | |
al (java.util.ArrayList. coll) | |
rnd (java.util.Random. seed)] | |
(java.util.Collections/shuffle al rnd) | |
(clojure.lang.RT/vector (.toArray al))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment