生成唯一随机ID

huangapple go评论85阅读模式
英文:

Creating unique random ID

问题

这会为Cloud Firestore创建一个唯一的用户ID吗?

Build.BOARD.length()+"" + Build.BRAND + Build.DEVICE + Build.DISPLAY.length()%10
+ Build.HOST.length()%10 + Build.ID.length()+ Build.MANUFACTURER.length()%10
+ Build.MODEL.length()%10 + Build.PRODUCT.length()%10 + Build.TAGS.length()%
10 + Build.TYPE + Build.USER.length()%10;
英文:

Would this create a unique user ID for Cloud Firestore?

Build.BOARD.length()+"" + Build.BRAND + Build.DEVICE + Build.DISPLAY.length() % 10
 + Build.HOST.length() % 10 + Build.ID.length() + Build.MANUFACTURER.length() % 10 
 + Build.MODEL.length() % 10 + Build.PRODUCT.length() % 10+ Build.TAGS.length() % 
 10 + Build.TYPE + Build.USER.length() % 10;

答案1

得分: 2

UUID

你考虑过使用通用唯一标识符(UUID)吗,例如通过UUID.randomUUID()方法返回的UUID?

UUID s = UUID.randomUUID();
System.out.println(s);

输出类似于

d918666e-6ebb-4700-99fe-c3279ba2daff

还有其他可用的UUID方法。但不能保证它绝对唯一,只是极高的概率上是唯一的。

英文:

UUID

Did you consider using a universally unique identifier (UUID) such as that returned by UUID.randomUUID()?

UUID s  = UUID.randomUUID();
System.out.println(s);

Prints something like

d918666e-6ebb-4700-99fe-c3279ba2daff

Additional UUID methods are also available. But no guarantees it would be unique. Just an extremely high probability that it is.

huangapple
  • 本文由 发表于 2020年6月29日 02:36:10
  • 转载请务必保留本文链接:https://go.coder-hub.com/62626699.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定