“随意”生成新的指南是否不负责任?如果是,或者不是,为什么?

发布于 2024-09-14 14:47:37 字数 144 浏览 1 评论 0原文

至少在 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 技术交流群。

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

发布评论

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

评论(5

北城孤痞 2024-09-21 14:47:37

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.

月亮坠入山谷 2024-09-21 14:47:37

只要您不是每时每刻都生成 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" ;)

如果没结果 2024-09-21 14:47:37

不会有 GUID 冲突:

在学习GUID的时候,感觉
好像38个区区数字还不够。
如果人们得到的话我们会不会用完
GUID-疯狂,将它们分配给
从他们的宠物到他们的一切
最喜欢的泡泡糖口味?

让我们看看。想想有多大
互联网是:谷歌拥有数十亿
其索引中的网页。我们就这样称呼它吧
万亿 (10^12) 的刺激。思考
关于每一篇维基百科文章,每一篇
CNN 新闻报道,每件产品
亚马逊,任何博客文章
作者。我们可以为每个项目分配一个 GUID
这些文件。

现在假设地球上的每个人都得到
他们自己的互联网副本
跟踪他们的东西。甚至
更疯狂的是,假设每个人都得到
他们自己的互联网副本
第二。我们还能持续多久?

超过十亿年。

更多信息请此处

There will be no GUID collisions:

When learning about GUIDs, it feels
like 38 measly digits aren’t enough.
Won’t we run out if people get
GUID-crazy, assigning them for
everything from their pets to their
favorite bubble gum flavor?

Let’s see. Think about how big the
Internet is: Google has billions of
web pages in its index. Let’s call it
a trillion (10^12) for kicks. Think
about every wikipedia article, every
news item on CNN, every product in
Amazon, every blog post from any
author. We can assign a GUID for each
of these documents.

Now let’s say everyone on Earth gets
their own copy of the internet, to
keep track of their stuff. Even
crazier, let’s say each person gets
their own copy of the internet every
second. How long can we go on?

Over a billion years.

More here.

找个人就嫁了吧 2024-09-21 14:47:37

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.

×纯※雪 2024-09-21 14:47:37

另一方面,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.

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