random-uuid

functionsince v0.0-3308Edit
(random-uuid)

Source docstring:
Returns a pseudo-randomly generated UUID instance (i.e. type 4).
Source code @ clojurescript:src/main/cljs/cljs/core.cljs
(defn random-uuid
  []
  (letfn [(^string quad-hex []
            (let [unpadded-hex ^string (.toString (rand-int 65536) 16)]
              (case (count unpadded-hex)
                1 (str "000" unpadded-hex)
                2 (str "00" unpadded-hex)
                3 (str "0" unpadded-hex)
                unpadded-hex)))]
    (let [ver-tripple-hex ^string (.toString (bit-or 0x4000 (bit-and 0x0fff (rand-int 65536))) 16)
          res-tripple-hex ^string (.toString (bit-or 0x8000 (bit-and 0x3fff (rand-int 65536))) 16)]
      (uuid
        (str (quad-hex) (quad-hex) "-" (quad-hex) "-"
             ver-tripple-hex "-" res-tripple-hex "-"
             (quad-hex) (quad-hex) (quad-hex))))))