Generate UUID in ClojureScript

ClojureScript has a built-in function to generate pseudo-random version 4 UUIDs


(random-uuid)

Note that since ClojureScript is a JavaScript based language, we can also use the same methods and libraries JavaScrip itself has. So, the simplest way to generate a UUID is using crypto.randomUUID() which produced a valid random version 4 UUID. This function is only available when your page is served from localhost or via https


(.randomUUID crypto)

If you need to generate a specific UUID version, you need to use a third-party library such as uuid


(require '[clj-uuid :as uuid])

;;generate UUID version 1 in ClojureScript
(uuid/v1)

;;generate UUID version 3 in ClojureScript using a
;; version 4 random UUID as the namespace and a custom name
(uuid/v3)

;;generate UUID version 4 in ClojureScript
(uuid/v4)

;;generate UUID version 5 in ClojureScript using a
;; version 4 random UUID as the namespace and a custom name
(uuid/v5 (uuid/v4) "name")

;;generate UUID version 6 in ClojureScript
(uuid/v6)

;;generate UUID version 7 in ClojureScript
(uuid/v7)

Since ClojureScript is based on JavaScript any JavaScript libraries such as uuid will also work. The Online UUID Generator on this site was implemented using this library, so another way to see it in action is to open it and view the page source.

How do I generate UUID in...

Find out how to generate UUIDs in your favorite language here: Bash, Groovy, Kotlin, Python, Scala, Clojure, Java, JavaScript, or return to Online UUID Generator