Skip to content

Instantly share code, notes, and snippets.

@maxp
Created September 1, 2017 02:26
Show Gist options
  • Save maxp/d59fd3f05980a65427a8239192543ee3 to your computer and use it in GitHub Desktop.
Save maxp/d59fd3f05980a65427a8239192543ee3 to your computer and use it in GitHub Desktop.
(import [java.util UUID])
(defn timebased-uuid []
(let [uuid (UUID/randomUUID)
time (int (/ (System/currentTimeMillis) 1000))
high (.getMostSignificantBits uuid)]
(UUID.
(bit-or
(bit-and high 0x00000000FFFFFFFF)
(bit-shift-left time 32))
(.getLeastSignificantBits uuid))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment