生成long类型的UUID [英] generate UUID of long type

查看:2163
本文介绍了生成long类型的UUID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请给我示例代码,以便在不使用时间戳的情况下在java中生成 UUID long 类型。

Please give me sample code to generate UUID of long type in java without using timestamp.

谢谢

推荐答案

真正的UUID是128位。长是64位。

A real UUID is 128 bits. A long is 64 bits.

这不仅仅是迂腐。 UUID代表通用唯一标识符。

This is not just pedantry. UUID stands for Universal Unique IDentifier.

已建立的UUID计划基于:


  • 编码MAC地址和时间戳,

  • 使用122位随机数编码DNS名称和时间戳的哈希值,或

  • ...这个值足够大碰撞的可能性非常小。

对于64位,通用唯一性根本没有足够的位。例如,生日悖论意味着如果我们有许多计算机生成随机的64位数字,那么潜在可检测到的碰撞的概率就足以引起关注。

With 64 bits, there are simply not enough bits for "universal uniqueness". For instance, the birthday paradox means that if we had a number of computers generating random 64 bit numbers, the probability of a potentially detectable collision would be large enough to be of concern.

现在,如果您只想要一个UID(不是UUID),那么任何64位序列生成器都可以完成这项工作,只要您采取措施防止重复序列。 (如果序列重复,则ID在时间上不是唯一的;即,随着时间的推移,给定的ID可能表示不同的实体。)

Now if you just want a UID (not a UUID), then any 64-bit sequence generator will do the job, provided that you take steps to guard against the sequence repeating. (If the sequence repeats, then the IDs are not unique in time; i.e. over time a given ID may denote different entities.)

这篇关于生成long类型的UUID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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