简体   繁体   English

Android中的UUID.randomUUID冲突

[英]UUID.randomUUID collision in Android

I understand that UUID.randomUUID is mostly good: how good is java's UUID.randomUUID? 我知道UUID.randomUUID主要是好的: java的UUID.randomUUID有多好?

Has anyone experienced a problem on Android with UUID.randomUUID. 有没有人在Android上遇到过UUID.randomUUID问题。 Since Android uses Dalvik VM. 由于Android使用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! 任何想法/经验都将有所帮助!

As I can see, http://docs.oracle.com/javase/7/docs/api/java/util/UUID.html the least significant digits consist in three fields: 如我所见, http://docs.oracle.com/javase/7/docs/api/java/util/UUID.html最低有效数字包括三个字段:

 0xC000000000000000 variant
 0x3FFF000000000000 clock_seq
 0x0000FFFFFFFFFFFF node

By not taking all the UUID, you are increasing your chances of collisions. 通过不使用所有UUID,您将增加发生碰撞的机会。 How about taking all of it like: private static final String PREFIX = UUID.randomUUID().toString(); 如何将其全部处理为: private static final String PREFIX = UUID.randomUUID().toString();

By that way, you will mitigate your chance of collision. 这样,您将减少碰撞的机会。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM