Skip to content

Instantly share code, notes, and snippets.

@tomjack
Created May 21, 2011 23:39
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/9fd979fdaef47ea67da0 to your computer and use it in GitHub Desktop.
Save tomjack/9fd979fdaef47ea67da0 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> (let [r (java.util.Random.)] [(permute {0 1 2 3} r) (permute {2 3 0 1} r)])
[{1 3, 0 1} {0 1, 1 3}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment