GUID (globally unique identifier)
The globally unique identifier (guid,globally unique Identifier) is a numeric identifier generated by the algorithm with a binary length of 128 bits. GUIDs are primarily used in networks or systems that have multiple nodes, multiple computers.
Ideally, no computer or computer cluster will generate two identical GUIDs.
The total number of GUIDs reaches 2^128 (3.4x10^38), so the probability of randomly generating two identical GUIDs is very small, but not 0.
The term GUID also sometimes refers to Microsoft's implementation of the UUID standard.
Ideally, no computer or computer cluster will generate two identical GUIDs. The probability of randomly generating two identical GUIDs is very small, but not 0.
Therefore, the algorithm used to generate the GUID usually adds non-random parameters (such as time) to ensure that this repetition does not occur.
On the Windows platform, GUIDs are widely used in Microsoft products to identify objects such as registry keys, class and interface identities, databases, system catalogs, and so on.
Chinese name Global Unique identifier foreign name guid,globally unique Identifier type numeric identifier acting on a multi-node, multi-computer network or system format
The format of the GUID is "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", where each x is a 4-bit hexadecimal number in the range of 0-9 or a-f. For example, 6F9619FF-8B86-D011-B42D-00C04FC964FF is a valid GUID value.
Characteristics
★ When a GUID is required, it can be generated automatically by the algorithm and does not require an authoritative authority to manage it.
★guid can theoretically produce the world's only value, which is convenient for future data import.
Dispute
The potential drawbacks of the GUID values have aroused the concern of the privacy advocates. In March 1999, the U.S. Federal Commerce Commission was asked to investigate Microsoft's use of GUID values. The controversy primarily involves the use of GUID values for Office 97 and Office 2000 documents. An Office document, such as a Word file or an Excel spreadsheet, uses a GUID value that is not visible to the user. However, there are many reports that the author of the document can be traced by a trace of the GUID value, even if the author has taken a special approach, they can be traced. In response to these questions, Microsoft has released an Office 97 patch SR2, which prohibits the use of the GUID feature and can also remove the GUID of an existing document.
The potential for misuse of Intel processor serial numbers is essentially the same as the problem with the above GUID values.
The GUID is a 128-bit integer (16 bytes) that can be used for all computers and networks that require a unique identifier. The likelihood of repetition of this identifier is very small. "
In the original English language, the questioner said he wanted to prove in a test program that the GUID is not unique, and then gives the following code implementation:
123 |
BigInteger begin = new BigInteger(( long )0); BigInteger end = new BigInteger( "340282366920938463463374607431768211456" ,10); //2^128 for (begin; begin<end; begin++) Console.WriteLine(System.Guid.NewGuid().ToString()); |
Unfortunately, "It's not working" (in fact, the code is copied to VS, the compilation fails, the BigInteger constructor does not exist at all, the For loop is not written at all, it is estimated to be pseudo-code).
Then we see the right answer with the most votes:
GuidcollisiondetectorUsing System;Using System.Collections.Generic;Using System.Linq;Namespace guidcollisiondetector{Class Program {Staticvoid Main (String[] args) {var reservesomeram =Newbyte[1024 * 1024 * 100]; Console.WriteLine ("{0:u}-Building a bigheapoguids. ", DateTime.Now);Fill up memory with GUIDs. var bigheapoguids =New Hashset<guid> ();try {do {Bigheapoguids.add (Guid.NewGuid ());}while (true); }catch (OutOfMemoryException) {Release The ram we allocated up front. Gc. KeepAlive (Reservesomeram); Gc. Collect (); } Console.WriteLine ("{0:u}-Built Bigheapoguids, contains {1} of them. ", DateTime.Now, Bigheapoguids.longcount ());Spool up some threads to keep checking if there ' s a match.Keep running until the heat death of the universe.for (Long k = 0; K < Int64.maxvalue; k++) {For (long j = 0; J < Int64.maxvalue; J + +) {Console.WriteLine ("{0:u}-looking for collisions with {1} thre AD (s) .... ", DateTime.Now, Environment.processorcount); System.Threading.Tasks.Parallel.For (0, Int32.MaxValue, (i) + = { if (Bigheapoguids.contains (Guid.NewGuid ())) throw New ApplicationException ("Guids collided! Oh my gosh! ");}); Console.WriteLine ("{0:u}-that is another {1} attempts without a collision.", DateTime.Now, ((long) int32.maxval UE) * environment.processorcount); }} Console.WriteLine ("umm ... why hasn ' t the Universe ended yet?"); }}}
1, the definition of a byte array reservesomeram, allocating a piece of memory space;
2, through the HashSet object to fill the GUID, until the memory is insufficient, through the GC's KeepAlive and collect method, frees up the memory space reserved to the Reservesomeram, guarantees the program to continue to run the small memory space (at this time, Lou Pig exclaimed, A good period of shocking artifice NB code AH);
3, through two for loop, with parallel library, through the contains function of HashSet to prove that the newly generated GUID is likely to produce duplicates (this is mainly the CPU operation of the thing, completely less than reservesomeram that piece of memory, fully utilize the CPU and memory , such a state of mind is really unbelievable, bull).
But see the "throw new ApplicationException" in the Code ("Guids collided! Oh my gosh! ");" and Console.WriteLine ("umm ... why hasn ' t the Universe ended yet
In comparison, personal feeling or this answer is more reliable:
Well if the running time's billion years does not scare you, think so you'll also need to store the generated GUID s somewhere to check if you have a duplicate; Storing 2^128 16-byte numbers would only require your to allocate 4951760157141521099596496896 terabytes of RAM upfront, so Imagining you has a computer which could fit all that and so you somehow find a place to buy terabyte DIMMs at ten gram s each, combined they'll weigh more than 8 Earth masses, so can seriously shift it off the current orbit, before Even press "Run". Think twice!
In general, it takes about 83 billion years and 4951760157141521099596496896 TB (1TB=1024GB) of memory space to run the certification process (assuming that each DIMM has 10 grams of memory, all the memory is converted to weight, About 8 of the weight of the Earth). From seemingly limited and infinite time and space, it is proved that the possibility that the GUID repeats this probability happens is that the wife is too small, can think basically impossible. One reply said, "Personally, I think the" big Bang "was caused when two GUIDs collided.", that is: Two GUIDs repeat the day of the Big Bang.
GUID (globally unique identifier)