Skip to content

Instantly share code, notes, and snippets.

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 patham9/789a459c1ba1113de7864dc0f337dbdc to your computer and use it in GitHub Desktop.
Save patham9/789a459c1ba1113de7864dc0f337dbdc to your computer and use it in GitHub Desktop.
(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