“随意”生成新的指南是否不负责任?如果是,或者不是,为什么?
至少在 C# 中,生成新的 GUID 是一个一行一调用过程。
指南易于使用和格式化,并且“保证”唯一性。
然而,仅仅为每件小事生成新的指南是不负责任的吗?我们能否显着增加“ta tan tan”引导碰撞的机会?!
想法...?
in c#, at least, generating a new guid is a one line one call process.
A guid is easy to use and format, and it "guarantees" uniqueness.
However, is it irresponsible to just go off and generate new guids for every little thing. Could we be significantly increasing the chances of a "ta tan tan" guid collision?!
thoughts...?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
GUID 是 128 位值。你可以每秒产生一百万个,直到太阳烧尽并且不会遇到碰撞。具体来说,应用于 128 位值的生日悖论意味着即使使用 10e19 值,发生冲突的可能性仍然只有 50%。
更具体地说,由于其表达方式,您所说的 10e38 或“38 位数字”看起来只是一个微不足道的数字。尝试将其写在一张纸上,即 1 后面有 38 个零。即使这样,你也可能无法想象它所代表的东西。要做到这一点,以某种方式分解它更容易。最好的方法是说明一些比较值。
一年有 10e7.5 秒。
地球上有10e9.8人。
目前宇宙的年龄有10e10.1年。
因此,即使目前地球上的每个人从一开始就每秒生成一百万个 GUID,您仍然只会使用不到 1/10,000 的域。
GUID's are 128 bit values. You could generate a million a second until the sun burned out and not encounter a collision. Specifically, the birthday paradox applied to a 128 bit value means even with 10e19 values, you still only have a 50% chance of a collision.
More specifically, 10e38 or '38 digits' as you say only seems like a measly number because of the way its expressed. Try writing it out on a piece of paper as a 1 with 38 zeros after it. Even then you probably can't picture anything like what it represents. To do that its easier to break it down somehow. The best way to do that is to illustrate some comparative values.
There are 10e7.5 seconds in a year.
There are 10e9.8 people on earth.
There are 10e10.1 years in the current age of the universe.
So even if every person currently on earth generated a million GUIDs every second since the beginning of time you would still only have used up less than 1/10,000th of the domain.
只要您不是每时每刻都生成 10000 个 GUID,我怀疑就会出现问题。 GUID 包含时间组件,因此保证在不同秒内生成的 GUID 是唯一的。
对于在一秒钟内生成的 GUID,该算法还包括一个随机发生器,因此您可能也不必担心这一点。我不记得这个领域有多大,但它应该大致“足够大”;)
As long as you're not generating 10000 GUIDs every moment, I doubt there's a problem. GUIDs include a temporal component, so GUIDs generated in different seconds are guaranteed to be unique.
For GUIDs generated within a second, the algorithm also includes a randomizer, so you probably don't have to worry about that either. I can't remember how big this field is off the top of my head, but it should be roughly "big enough" ;)
不会有 GUID 冲突:
更多信息请此处。
There will be no GUID collisions:
More here.
GUID 可以通过多种方式生成;最常见的是散列
在任何给定时间点可能是唯一的一些东西,例如 IP
地址加上时钟日期/时间等用于生成唯一 ID。
每个系统可能有稍微不同的算法来生成唯一的
ID。
除此之外,请考虑您使用 GUID 的范围。您的应用程序不可能生成相同的 GUID。
GUIDs can be generated in a number of ways; most often a hash of
several things that might be unique at any given point in time like the IP
address plus the clock date/time etc are used to generate Unique Ids.
Each system may have slightly different algorithm to generate the Unique
Id.
Besides that think of the scope you are using your GUIDs in. It's not possible your app generates identical GUIDs.
另一方面,GUID 的制作成本往往有点高,而且处理和使用起来也很笨拙。没有什么比破译无数看起来相似的 32 个 CHAR ID 更有趣的了。
The other side of the coin is that GUIDs tend to be a bit expensive to make, and ungainly to process and use. Nothing more fun that deciphering a zillion 32 CHAR IDs that sorta look alike.