Skip to content

Instantly share code, notes, and snippets.

@tomjack
Created May 21, 2011 23:42
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 tomjack/35f2c6854ad0e721cf89 to your computer and use it in GitHub Desktop.
Save tomjack/35f2c6854ad0e721cf89 to your computer and use it in GitHub Desktop.
(defn shuffle-rand [coll rand]
(let [al (java.util.ArrayList. coll)]
(java.util.Collections/shuffle al rand)
(clojure.lang.RT/vector (.toArray al))))
(defn permute [v rand]
(zipmap (shuffle-rand (range (count v)) rand) (vals v)))
scratch.vectors> (map permute [{0 1 2 3} {2 3 0 1}] (repeatedly #(java.util.Random. 57357357357)))
({1 3, 0 1} {1 1, 0 3})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment