Created
October 24, 2011 15:34
-
-
Save renan/1309330 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Two identical UUIDs in a row | |
How hard is it to generate two identical UUIDs in a row? Or, to put it another way, what’s the probability that two random UUID’s in a random set are identical? Well, the chance is the same as that you would generate one of those, you may try it!: | |
In fact you can’t do this. This is as much possible as tossing a coin 128 times in a row resulting with 128 heads (or tails) in a row. In Lotto game where you choose six numbers out of 49, winning is as probable as obtaining 24 heads in a row. You may try it yourself too | |
To say it another way, if one random UUID was a tile of area 1 mm2, when placed each by each other they would take some… 6,671,261,450,000,000,00 surfaces of Earth (including oceans). Imagine yourself on such an „infinite” tiled floor, what are the odds that you will find just the right tile once you know one is of a different color on the other side? | |
What about birthday paradox | |
Well, when you are considering using GUID as a key in your database, you certainly are going to have more than two records there. The more keys you generate, the more probability increases, as now you have potential collisions with all items that already exist. This is known as the birthday paradox. So how dangerous is it this time? | |
The graphs published in the article « Probability of duplicate GUID » shows the probability in function of the number of generated GUIDs. It generally says it’s practivally impossible. To illustrate it, I’ll just present one more stupid example at the end. | |
Let’s assume that Facebook, Myspace or any other promising player conquered the whole global market (of population near 7,000,000,000 users). Now let’s assume that every time user clicks ‘like’ button, we want to celebrate this event with assigning a new random GUID to it. If everyone likes 10 new things a day on average, after 100 years of such clicking the chance that any two of these GUIDs collided is some 0,00000192%. The chance you get killed by meteorite is still 100 times greater (not to mention lightnings, venomous snakes etc.). And the question is, what is the chance we will remember Facebook in 100 years? | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment