java.util.UUID.randomUUID().toString()length
作者:互联网
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
那种类型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 hex char 4连字符char = 36 char.所以长度总是一样的.
更新:
I do not know what type 4 means in the case.?
仅供参考:有几种方法可以生成UUID.这里类型4表示使用随机或伪随机数生成此uuid.来自wiki – 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.
标签:string-length,java,string,random,uuid 来源: https://codeday.me/bug/20190930/1836766.html