1

I understand that UUID.randomUUID is mostly good: how good is java's UUID.randomUUID?

Has anyone experienced a problem on Android with UUID.randomUUID. Since Android uses Dalvik VM.

I am not able to reproduce a collision. However, the following code is suspicious (based on reports from my Production) and may result into a collision while running on two different processes (Two apps with the same code and different packages, for example free app vs pro app)?

private static final String PREFIX = Long.toString(UUID.randomUUID().getLeastSignificantBits());

Any thoughts/experience would be helpful!

Community
  • 1
  • 1
ssk
  • 9,045
  • 26
  • 96
  • 169

1 Answers1

1

As I can see, http://docs.oracle.com/javase/7/docs/api/java/util/UUID.html the least significant digits consist in three fields:

 0xC000000000000000 variant
 0x3FFF000000000000 clock_seq
 0x0000FFFFFFFFFFFF node

By not taking all the UUID, you are increasing your chances of collisions. How about taking all of it like: private static final String PREFIX = UUID.randomUUID().toString();

By that way, you will mitigate your chance of collision.

JFPicard
  • 5,029
  • 3
  • 19
  • 43