0

I need to a unique and 64-bit ID Generator? I know that UUID is 128 bit but If exist any version of id generator in java get it to me. It's important that the ids are not sequence.

  • You can always use a non-repeating pseudo-random number generator. – Hot Licks May 07 '14 at 11:27
  • @HotLicks : I thought the usual interpretation of random generator period was that they didn't restart the exact same sequence, not that they didn't emit the same number? – monocell May 07 '14 at 12:53
  • @monocell - Depends on the RNG. There is no single definition that encompasses everything. – Hot Licks May 07 '14 at 15:14

2 Answers2

3

The least significant half of a UUID in Java is very unique, and that would give you a 64bit number.

UUID.randomUUID().getLeastSignificantBits()

Also see: Likelihood of collision using most significant bits of a UUID in Java

As pointed out in the comments, the number is not guaranteed unique, but duplications are unlikely

Community
  • 1
  • 1
Leon
  • 12,013
  • 5
  • 36
  • 59
0

you could use a Blowfish encryption over a normal counter, or generate a UUID4 and xor the first and last 16 bytes.

Amir Arad
  • 6,724
  • 9
  • 42
  • 49