java.util.UUID.randomUUID().toString()长度 [英] java.util.UUID.randomUUID().toString() length
问题描述
java.util.UUID.randomUUID().toString()的长度是否始终等于36?
Does java.util.UUID.randomUUID().toString() length always equal to 36?
我找不到有关的信息. 此处仅说以下内容:
I was not able to find info on that. Here it is said only the following:
公共静态UUID randomUUID() 静态工厂检索类型4(伪随机生成)的UUID.使用加密强度高的伪随机数生成器生成UUID. 返回值: 随机生成的UUID
public static UUID randomUUID() Static factory to retrieve a type 4 (pseudo randomly generated) UUID. The UUID is generated using a cryptographically strong pseudo random number generator. Returns: A randomly generated UUID
那type 4
告诉我什么都没有.我不知道类型4在这种情况下是什么意思.
And that type 4
tells me nothing. I do not know what type 4 means in the case.
推荐答案
java.util.UUID.randomUUID().toString()的长度是否始终等于36?
Does java.util.UUID.randomUUID().toString() length always equal to 36?
是的!是.
A UUID
实际上是一个128位值(2个长整数).为了将128位表示为十六进制字符串,将有128/4=32
char(每个char为4位长).字符串格式还包含4(-
),这就是长度为36的原因.
Yes!! it is.
A UUID
actually a 128 bit value (2 long). To represent 128 bit into hex string there will be 128/4=32
char (each char is 4bit long). In string format it also contains 4 (-
) that's why the length is 36.
32个十六进制字符+ 4个连字符= 36个字符.因此长度将始终相同.
32 hex char + 4 hyphen char = 36 char. So the length will be always same.
在这种情况下,我不知道类型4是什么意思??
I do not know what type 4 means in the case.?
FYI:有几种生成UUID的方法.这里的类型4表示该uuid是使用随机数或伪随机数生成的.摘自Wiki- Universally_unique_identifier#Versions :
FYI: There are several ways of generating UUID. Here type 4 means this uuid is generated using a random or pseudo-random number. From wiki - Universally_unique_identifier#Versions:
版本
对于变体1和2,标准中定义了五个版本",在特定的用例中,每个版本可能比其他版本更合适.版本由字符串表示形式中的M表示.
Versions
For both variants 1 and 2, five "versions" are defined in the standards, and each version may be more appropriate than the others in specific use cases. Version is indicated by the M in the string representation.
版本1 是根据时间和节点ID(通常是MAC地址)生成的UUID;
Version 1 UUIDs are generated from a time and a node id (usually the MAC address);
版本2 UUID由标识符(通常是组或用户ID),时间和节点ID生成;
version 2 UUIDs are generated from an identifier (usually a group or user id), time, and a node id;
版本3和5 产生确定性的UUID,这些UUID是通过对命名空间标识符和名称进行哈希处理而产生的;
versions 3 and 5 produce deterministic UUIDs generated by hashing a namespace identifier and name;
和版本4 UUID是使用随机数或伪随机数生成的.
and version 4 UUIDs are generated using a random or pseudo-random number.
这篇关于java.util.UUID.randomUUID().toString()长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!