How many guids are possible
Yes, a GUID should always be unique. It is based on both hardware and time, plus a few extra bits to make sure it's unique. I'm sure it's theoretically possible to end up with two identical ones, but extremely unlikely in a real-world scenario.
Guids are statistically unique. The odds of two different clients generating the same Guid are infinitesimally small assuming no bugs in the Guid generating code. Multiple threads allocating new guids will get unique values, but you should get that the function you are calling is thread safe. Which environment is this in? There are on the order 2 30 personal computers in the world and of course lots of hand-held devices or non-PC computing devices that have more or less the same levels of computing power, but lets ignore those.
Let's assume that we put all those PCs in the world to the task of generating GUIDs; if each one can generate, say, 2 20 GUIDs per second then after only about 2 72 seconds -- one hundred and fifty trillion years -- you'll have a very high chance of generating a collision with your specific GUID. And the odds of collision get pretty good after only thirty trillion years. Theoretically, no, they are not unique.
It's possible to generate an identical guid over and over. However, the chances of it happening are so low that you can assume they are unique. I've read before that the chances are so low that you really should stress about something else--like your server spontaneously combusting or other bugs in your code. That is, assume it's unique and don't build in any code to "catch" duplicates--spend your time on something more likely to happen i.
I made an attempt to describe the usefulness of GUIDs to my blog audience non-technical family memebers. To put that number into perspective, lets take machines, each having a 4 core CPU, doing 4Ghz and spending cycles to generate a Guid and doing nothing else. It is a bit integer number used to identify resources.
Not guaranteed, since there are several ways of generating one. However, you can try to calculate the chance of creating two GUIDs that are identical and you get the idea: a GUID has bits, hence, there are 2 distinct GUIDs — much more than there are stars in the known universe. Read the wikipedia article for more details. MSDN :. There is a very low probability that the value of the new Guid is all zeroes or equal to any other Guid.
In practice, the number of people who break the rules is low, and their GUIDs are unlikely to "escape". Conflicts are statistically improbable. I use the Neat Receipts desktop scanner and it comes with proprietary database software. The software has a sync to cloud feature, and I kept getting an error upon syncing. A gander at the logs revealed the awesome line:.
I was a bit in disbelief, but surely enough, when I found a way into my local neatworks database and deleted the record containing that GUID, the error stopped occurring. So to answer your question with anecdotal evidence, no. A duplicate is possible. But it is likely that the reason it happened wasn't due to chance, but due to standard practice not being adhered to in some way.
I am just not that lucky However, I cannot say for sure. It isn't my software. FWIW, I am very impressed by Neat, and this glitch, however frustrating, didn't change my opinion of their product.
For more better result the best way is to append the GUID with the timestamp Just to make sure that it stays unique. I guess that has to do with, all other tings being equal, the identical seeding or lack of seeding of pseudo random generators.
I was using it for generating unique file names. I found the OS is much better at doing that :. That depends on the number of GUIDs it must be unique among. In a more general sense, this is known as the "birthday problem" or "birthday paradox". Wikipedia has a pretty good overview at: Wikipedia - Birthday Problem. Of course, that is just the ideal case of a truly random process. As others mentioned, a lot is riding on the that random aspect - just how good is the generator and seed?
It would be nice if there was some hardware support to assist with this process which would be more bullet-proof except that anything can be spoofed or virtualized. Sadly, these fall into the category of "likely non-unique" , from Wikipedia I don't know why so many people ignore this bit : " The pseudo-random properties of V8's JavaScript Math.
Because it's becoming more and more common to scale ID generation across multiple clients, and clusters of servers, entropy takes a big hit -- the chances of the same random seed being used to generate an ID escalate time is often used as a random seed in pseudo-random generators , and GUID collisions escalate from "likely non-unique" to "very likely to cause lots of trouble".
To solve this problem, I set out to create an ID algorithm that could scale safely, and make better guarantees against collision. It does so by using the timestamp, an in-memory client counter, client fingerprint, and random characters. The combination of factors creates an additive complexity that is particularly resistant to collision, even if you scale it across a number of hosts:.
The hardest part is designed a database to store all of the generated ones to check if it is actually duplicated. This number is equivalent to generating 1 billion UUIDs per second for about 85 years, and a file containing this many UUIDs, at 16 bytes per UUID, would be about 45 exabytes, many times larger than the largest databases currently in existence, which are on the order of hundreds of petabytes.
In Detail: GUIDs are designed to be unique; they are calculated using a random method based on the computers clock and computer itself, if you are creating many GUIDs at the same millisecond on the same machine it is possible they may match but for almost all normal operations they should be considered unique. Enough GUIDs to assign one to each and every hypothetical grain of sand on every hypothetical planet around each and every star in the visible universe.
Given the number of current local uses for GUIDs one sequence per table per database for instance it is extraordinarily unlikely to ever be a problem for us limited creatures and machines with lifetimes that are usually less than a decade if not a year or two for mobile phones.
Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams?
Collectives on Stack Overflow. Learn more. Ask Question. Asked 13 years, 2 months ago. Active 3 months ago. Viewed k times. Will it stay unique over multiple threads? Improve this question. David Basarab David Basarab If it does not can you see a DHB being willing to foot the cost of the enhancment?
If all 6 billion people used guids or had them used on their behalf , each person could use per second for the average lifespan of 70 years. Sounds like guids have things covered for a little while. If you had that many pennies, Whitman and colleagues David Coleman and William Wiebe calculated, they would make a stack a trillion light years long. I don't know how long they live for BTW, judging by comments, this is the most successful blog post I have ever made - go figure.
Cars have VINs , even people have social security numbers. Numbers help us reference items unambiguously. You may see the term UUID tossed about universally unique identifier , a nitpicky word for those whose numbers are unique not only within the globe, but throughout the entire universe.
The problem with counting is that we want to create ID numbers without the management headache. GUIDs are large, enormous numbers that are nearly guaranteed to be unique. They are usually bits long and look like this in hexadecimal :. The format is a well-defined sequence of 32 hex digits grouped into chunks of GUIDs are not tied to a product. A GUID can be used for people, cars, files, webpages, colors, anything. With regular registration numbers, you start counting at 1 and numbers can overlap.
There are so many GUIDs that you can use them to number everything and not run out. GUIDs give you a unique serial number that can be used on any item in the universe. Think about how big the Internet is: Google has billions of web pages in its index. 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. How long can we go on? Let me say that again. Each person gets a personal copy of the internet, every second, for a billion years.
0コメント