I want to generate time-based universally unique identifier (UUID) in Java.
The method java.util.UUID.randomUUID()
generates a UUID Version 4 where 122 of the 128 bits are from a cryptographically-strong random number generator.
How to generate a Version 1 (time based) UUID ? Is there a separate library for that or is it some how provided in the Java 7 API and I am missing it.
timestamp() . More precisely, a version 1 UUID stores a timestamp that represents the number of 100-nanoseconds intervals since midnight, 15 October 1582 and that is what uuid.
There are two different ways of generating a UUID. If you just need a unique ID, you want a version 1 or version 4. Version 1: This generates a unique ID based on a network card MAC address and current time. If any of these things is sensitive in any way, don't use this.
UUIDs are generated using an algorithm based on a timestamp and other factors such as the network address. Free tools to generate UUIDs include UUIDTools or Online UUID Generator.
The javadoc for UUID says the following about the timestamp field: The 60 bit timestamp value is constructed from the time_low, time_mid, and time_hi fields of this UUID. The resulting timestamp is measured in 100-nanosecond units since midnight, October 15, 1582 UTC.
FasterXML Java Uuid Generator (JUG)
https://github.com/cowtowncoder/java-uuid-generator
UUID uuid = Generators.timeBasedGenerator().generate();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With