Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate time based UUIDs?

Tags:

java

uuid

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.

like image 944
dogfish Avatar asked Aug 15 '13 01:08

dogfish


People also ask

Are UUIDs time based?

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.

Is UUID v4 time based?

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.

How do you generate UUID?

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.

Does UUID contain timestamp?

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.


1 Answers

FasterXML Java Uuid Generator (JUG)

https://github.com/cowtowncoder/java-uuid-generator

UUID uuid = Generators.timeBasedGenerator().generate(); 
like image 126
Vadzim Avatar answered Sep 29 '22 04:09

Vadzim