uuid – 为什么版本4 GUID的第17位数仅限于4种可能性?

据我所知,这并不会对所涉及的熵产生很大的影响,即使GUID的整个其他角色被保留(出于任何目的),我们仍然可以为每只昆虫提供足够的,,所以我并不担心,只是好奇.

this great answer所示,用于生成GUID的Version 4算法具有以下格式:

xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx

> x是随机的
> 4是常量,这表示版本号.
> y是以下之一:8,9,A或B.

RFC spec for UUIDs说必须以这种方式设置这些位,但我没有看到任何理由.

为什么第三个子弹(第17个数字)仅限于这四个数字?

最佳答案 引用可贵的Lippert先生

First off, what bits are we talking about when we say “the bits”? We already know that in a “random” GUID the first hex digit of the third section is always 4….there is additional version information stored in the GUID in the bits in the fourth section as well; you’ll note that a GUID almost always has 8, 9, a or b as the first hex digit of the fourth section. So in total we have six bits reserved for version information, leaving 122 bits that can be chosen at random.

(自https://ericlippert.com/2012/05/07/guid-guide-part-three/起)

tl; dr – 它是更多的版本信息.为了得到更具体的信息,我怀疑你将不得不追踪规范的作者.

点赞