Skip to content

Instantly share code, notes, and snippets.

@kriyative
Created June 23, 2014 02:52
Show Gist options
  • Save kriyative/54cc3bd55d231983247c to your computer and use it in GitHub Desktop.
Save kriyative/54cc3bd55d231983247c to your computer and use it in GitHub Desktop.
(defn uuid []
"Return an RFC1422 ver.4 compliant UUID"
(let [format "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx"
hex "0123456789abcdef"
gen #(case %
\x (get hex (rand-int 16))
\y (get hex (bit-or 0x8 (bit-and 0x3 (rand-int 16))))
%)]
(apply str (map gen format))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment