在 Java 中通过 UUID 生成唯一数字? [英] unique Number generation by UUID in Java ?

查看:123
本文介绍了在 Java 中通过 UUID 生成唯一数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在查看一段代码,我可以看到已经编写了以下代码来生成一个字符串,并且该字符串已被设置为表的主键.

I am looking at a piece of code, and i can see that the following code has been written which generates a string, and that string has been set as the primary key of the table.

return new BigInteger(UUID.randomUUID().toString().replaceAll("-", ""), 16).toString(36);

到目前为止,有很多记录,它们似乎是唯一的,因为没有违反主键约束.

Till now, there are lots of records and they seem to be unique as the primary key constraint is not violated.

我知道这个数字是随机的,但它会是唯一的吗?

I understand that the number will be random but will it be unique?

谢谢

图科

推荐答案

不能保证这些数字是唯一的,但是极不可能生成重复的数字,因为范围如此之大.

There is no guarantee that the numbers will be unique, however it is extremely improbable that a duplicate will ever be generated because there is such a huge range.

>

即使考虑到生日悖论,这种可能性也极低.

The chance is extremely low even after considering the birthday paradox.

这篇关于在 Java 中通过 UUID 生成唯一数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆