How to Generate UUIDs in Kotlin

Generate UUIDs in Kotlin with java.util.UUID for v4 and a library-backed approach for v7 on the JVM.

Recommendation: use native UUID v4 for simplicity, and add UUID v7 through a library when chronological ordering matters in your application.

How to generate UUID v4 in Kotlin

import java.util.UUID

val id = UUID.randomUUID()
println(id)

How to generate UUID v7 in Kotlin

// Gradle: implementation("com.github.f4b6a3:uuid-creator:...")
import com.github.f4b6a3.uuid.UuidCreator

val id = UuidCreator.getTimeOrderedEpoch()
println(id)

Native support notes

  • Kotlin/JVM inherits Java UUID behavior.
  • UUID v4 is native through the JVM UUID class.
  • UUID v7 is usually library-based.

Practical notes

  • Use the same UUID v7 library across Java and Kotlin modules to avoid drift.
  • UUID v4 is still the easiest option for Android-compatible or mixed-runtime code.
  • Link internal guidance to UUID v4 and UUID v7 documentation.

Frequently Asked Questions

On the JVM, it is mostly the same. Kotlin calls into the same underlying Java UUID APIs and libraries.

In most Kotlin/JVM projects, UUID v7 is added through a library rather than a standard built-in API.

Learn more

These articles expand on related concepts, formats and practical considerations.

By using this site, you agree to our Privacy Policy and Terms of Service. You are not permitted to use the GUIDs (also known as UUIDs) generated by this site or use any other content, services and information available if you do not agree to these terms.
Disclaimer: All information is provided for general educational and technical reference only. While we aim to keep the content accurate, current and aligned with published standards, no guarantees are made regarding completeness, correctness or suitability for any specific use case.
GUID specifications, best practices, security guidance, database behavior and ecosystem conventions (including cloud platforms and identifier formats) may change over time or differ by implementation. Examples, recommendations and comparisons are illustrative and may not apply universally.
This content should not be considered legal, security, compliance or architectural advice. Before making critical design, security or production decisions, always consult the latest official standards and vendor-specific documentation.
Always evaluate behavior in your own environment.
Standards Compliance: The GUIDs generated by this site conform to RFC 4122 and RFC 9562 specifications whenever possible, using cryptographically secure random number generation.