java.util.UUID.randomUUID().toString() 长度是否总是等于 36?
我无法找到这方面的信息。 Here据说只有以下几点:
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 是什么意思。
最佳答案
Does java.util.UUID.randomUUID().toString() length always equal to 36?
是的!!是的。
一个 UUID
实际上是一个 128 位的值(2 长)。要将 128 位表示为十六进制字符串,将有 128/4=32
字符(每个字符长 4 位)。在字符串格式中,它还包含 4 (-
),这就是长度为 36 的原因。
示例:54947df8-0e9e-4471-a2f9-9af509fb5889
32 个十六进制字符 + 4 个连字符 = 36 个字符。所以长度总是一样的。
更新:
I do not know what type 4 means in the case.?
仅供引用:有几种生成 UUID 的方法。这里类型 4 表示此 uuid 是使用随机或伪随机数生成的。来自维基 - Universally_unique_identifier#Versions :
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.
Version 1 UUIDs are generated from a time and a node id (usually the MAC address);
version 2 UUIDs are generated from an identifier (usually a group or user id), time, and a node id;
versions 3 and 5 produce deterministic UUIDs generated by hashing a namespace identifier and name;
and version 4 UUIDs are generated using a random or pseudo-random number.
关于java.util.UUID.randomUUID().toString() 长度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45388021/