猜测(匹配)Guid 的概率是多少?

发布于 2024-10-16 00:06:02 字数 143 浏览 1 评论 0原文

只是好奇,但匹配 Guid 的概率是多少?

说出 SQL Server 中的 Guid:5AC7E650-CFC3-4534-803C-E7E5BBE29B3D

它是阶乘吗?:(36*32)! =(1152)!

讨论 =D

Just curious but what is the probability of matching a Guid?

Say a Guid from SQL server: 5AC7E650-CFC3-4534-803C-E7E5BBE29B3D

is it a factorial?: (36*32)! = (1152)!

discuss
=D

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

扶醉桌前 2024-10-23 00:06:02

目前尚不清楚你在问什么。我看到有两种方法可以解释你的问题。

  1. 给定一个 GUID g,有人猜到它的概率是多少?为了简单起见,我们假设 GUID 的所有 128 位都可用。那么猜测g的概率是2^-128。那很小。让我们对此有一些直觉。假设我们的攻击者每秒可以生成 10 亿个 GUID。为了有 50% 的机会猜测 g,我们的攻击者必须生成 2^127 个 GUID。以每秒 10 亿的速度计算,需要 5391448762278159040348 年才能生成 2^127 个 GUID。

  2. 我们正在生成一个指南集合。发生碰撞的可能性有多大?也就是说,我们生成两个具有相同值的指导的可能性有多大?这就是生日悖论。如果随机生成一系列 n 个 GUID,则至少发生一次冲突的概率大约为 p(n) = 1 - exp(-n^2 / 2 * 2^128)(这是生日问题(可能的生日数量为 2^128)。

np(n)
2^30 1.69e-21
2^40 1.77e-15
2^50 1.86e-10
2^60 1.95e-03

因此,即使生成 2^60 个 GUID,发生冲突的可能性也非常小。如果每秒可以生成 10 亿个 GUID,则仍然需要 36 年才会有 1.95e-03 的碰撞机会。

It's not clear what you're asking. I see two ways to interpret your question.

  1. Given a GUID g, what is the probability of someone guessing it? Let's assume for simplicity that all 128 bits of a GUID are available. Then the probability of guessing g is 2^-128. That's small. Let's get some intuition around that. Let's assume that our attacker can generate one billion GUIDs per second. To have a 50% chance of guessing g, our attacker would have to generate 2^127 GUIDs. At a rate of one billion per second, it would take 5391448762278159040348 years to generate 2^127 GUIDs.

  2. We are generating a collection of guids. What is the likelihood of a collision? That is, what is the likelihood that we generate two guids with the same value? This is the birthday paradox. If you generate a sequence of n GUIDs randomly, then the probability of at least one collision is approximately p(n) = 1 - exp(-n^2 / 2 * 2^128) (this is the birthday problem with the number of possible birthdays being 2^128).

n p(n)
2^30 1.69e-21
2^40 1.77e-15
2^50 1.86e-10
2^60 1.95e-03

So, even if you generate 2^60 GUIDs, the odds of a collision are extremely small. If you can generate one billion GUIDs per second, it would still take 36 years to have a 1.95e-03 chance of a collision.

倾城月光淡如水﹏ 2024-10-23 00:06:02

可能的 GUID 数量(128 位值)为 2^128 或 3.4×10^38 — 地球整个体积的每立方毫米大约为 2 万亿个。

换句话说,有点低。

(地球卷参考来源:维基百科)

The number of possible GUIDs (128-bit value) is 2^128 or 3.4×10^38 — roughly 2 trillion per cubic millimeter of the entire volume of the Earth.

In other words, kind of low.

(Source for Earth volume reference: WikiPedia)

铃予 2024-10-23 00:06:02

取决于 GUID 生成算法的类型。当前算法使用 124 个随机位,因此概率为 2^124 中的 1。

对于较旧的算法(使用时间和 MAC 地址),概率要高得多。

Depends on the type of GUID generation algorithm. Current algorithms use 124 random bits so the probability is 1 in 2^124.

With older algorithms (that use time and MAC address) the probability is much higher.

烟酉 2024-10-23 00:06:02

您的计算有很多错误。
首先,36*32 意味着任何字母数字字符都可以成为 GUID 的一部分。事实并非如此;只允许使用十六进制字符。

其次,唯一 GUID 数量的计算为
有效字符数 (16: 0-9, AF) ^ GUID 长度 (32 个字符)

所以我们有 16^32 ==> 2^(4^32)==> 2^128

猜测任何一个 GUID 的几率是 1 / 2^128。

There are a number of things wrong with your calculations.
First off, 36*32 implies that any alphanumeric character can be part of the GUID. This is not the case; only HEX characters are allowed.

Secondly, the calculation for the number of unique GUIDs is
Number of Valid Characters (16: 0-9, A-F) ^ length of GUID (32 characters )

So we have 16^32 ==> 2^(4^32) ==> 2^128

The odds of guessing any one GUID is 1 / 2^128.

鹿港巷口少年归 2024-10-23 00:06:02

这取决于生成的 GUID 数量。这类似于统计学中的生日问题。请参阅维基百科和 http://betterexplained.com/articles/understand-the-birthday-paradox / (这个具体有一个 GUID 示例)

一般来说,在 N 个可能的 guid 上生成 M 个 guid 的冲突概率为 1 - (1- (1/N))^C(M, 2) 其中 C(M,2) 是“M​​ 选择 2”

It depends on how many GUIDs are generated. This is similar to the birthday problem in statistics. See Wikipedia and http://betterexplained.com/articles/understanding-the-birthday-paradox/ (this one specifically has a GUID example)

In general, the probability of a collision for generating M guids over N possible guids is 1 - (1- (1/N))^C(M,2) where C(M,2) is 'M choose 2'

失与倦" 2024-10-23 00:06:02

它是 1 /(给定 UID 长度可能的唯一数字的数量)。在上面的示例中,我们看到 16 个字节,即 128 位。 2^128,因此匹配的概率为 1 / 2^128。

It is 1 / (number of unique numbers possible with the given UID length). In the above example we see 16 bytes, or 128 bits. 2^128, so the probability of a match is 1 / 2^128.

心凉 2024-10-23 00:06:02

正确的计算方法是 2^128,因为我们处理的是 128 位。

但如果你想使用十六进制编号来计算它,那么你可以将其写为 16^32。

第一个数字有 16 种可能性 * 第二个数字有 16 种 * 第三个数字有 16 种……

在计算概率时,阶乘仅适用于某些组合相等的情况,例如在彩票数字中,156 相当于 561。

希望这会有所帮助。

The proper way to calculate this is 2^128 since we are dealing with 128 bits.

But if you want to calculate it using the hexadecimal numbering then you can write this as 16^32.

16 possibilities for the first number * 16 for the second * 16 for the third etc...

When calculating probabilities, factorials only apply if some combinations are equivalent such as in lottery numbers where 156 is equivalent to 561.

Hope this helps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文