- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
it's going to run out on the 21st of december this year. Will something happen? Maybe, maybe not. Who knows?
Admin
Lets analyze the function. If we find a unique GUID at the first try we have the best case of O(1).
But what about the worst case? What if the same GUID is generated 10 million times in a row? What if the same GUID is generated 10 billion times in a row? What if the same GUID is generated 10 trillion times in a row? What if the same GUID is generated 10 quadrillion times in a row? What if the same GUID is generated 10 quintillion times in a row? What if the same GUID is generated 10 sextillion times in a row? What if the same GUID is generated 10 septillion times in a row? What if the same GUID is generated 10 octillion times in a row? What if the same GUID is generated 10 nonillion times in a row? What if the same GUID is generated 10 decillion times in a row? What if the same GUID is generated 10 undecillion times in a row? What if the same GUID is generated 10 duodecillion times in a row?
We see the worst case is actually O(infinity). That gives a complexity of O(infinity/2) in the average case which is clearly inacceptable. To be on the safe side we need the possibility to pass a timeout to the function.
Admin
The method should be refactored to
just in case the built-in GUID generator implementation does not generate unique-enough GUIDs.
Admin
Admin
-Harrow.
Admin
That's why smart people run away from crappy systems like Oracle and Java and similar undocumented crap like Unix.
Admin
I know - a day won't pass that I don't stumble upon a dumbass.
Admin
TRWTF is that this function could loop infinitely.
An obviously-better implementation would be to apply a Cantor diagonalization scheme to the given list of GUIDs.
Admin
"Premature protection" ... like buying an umbrella on a day when it isn't raining; or getting life insurance even though you have, so far, never died.
Admin
Or wearing a rubber with the rest of your daily attire in the event that it might be useful for once.
Admin
While (comments.Next) If Comment.equals ('Frist') DifferentComment('Secunt')
Admin
Man, you have that problem too? How do you take care of it?
Admin
Thankfully, this is illegal in enlightened states.
Admin
Captcha: mara
This is only significant because it's the first time that my captcha was already present in my browser's autocomplete. So you could say I had a collision. Maybe we need to start using GUIDs for captchas?
Admin
All the suggestions as to how to do it "safer" presented above are silly. It's obvious how it should be done.
Register a domain, call it "tehguids.net"
Every enterprise that generates guids gets their own server on a subdomain there, serving a linked page of guids it generated since its inception.
Everytime a suggested guid is to be passed from the API to the caller, a google search is done with site:tehguids.net to ensure no such GUID was issued beforehand.
Simple, scalable, leverages teh cloud, and in case of offline generation you use whatever OS api/library is there for the guid generation, but you double-check things when you get back online, and if there are collisions, the fix is only a quick sql UPDATE query away.
Admin
Actually we ran into a situation where we had many (~2%) GUID-Collisions! It was a mobile system without a MAC-Address and only a default time on boot-up...
Admin
I don't know if this is mentioned, but depending on how the "Any" method works, there could be a subtle bug in this code. (I don't know which language this is, so I can't look it up, and "Any" is such a vague term to Google.)
Does Any() recheck the guids it checked before, when result gets a new guid? If not, it could end up colliding with a previously-checked guid after colliding with one later in the array. In which case, I want that guy's lottery tickets.
Admin
Well, in a given year, one's chance of being struck by a meteorite is 1 in 1.710^10; as such, one's chance of being struck by a meteorite during a one-hour period on any Tuesday during Lent (43 days) is about 1 in 2.110^13, or 1 in 1.5*10^14 on any given one of these days.
The chance of winning the Lotto jackpot on a given night with random numbers is about 1 in 1.410^7. By multiplying this by 1 in 1.510^14, we find that the probability of being struck by a meteor and winning the lottery on a given Tuesday is 1 in 2.110^21; doing this on one of six days, the odds are 1 in 3.510^20.
Though the other things are personal choices, I'll factor them in anyway:
~7,000 Ferraris were produced in 2011; if we extrapolate this over 65 years of Ferraris existing, there are about 455,000 Ferraris, meaning that there is about a 1 in 15,385 chance that a particular person owns one.
I couldn't find any pancake-related statistics, but IHOP served about $50M of pancakes to Americans in 2006, so the probability of a particular American eating pancakes on a given day is about 1 in 2192.
If we multiply all of this together, we find that the odds of doing all that are about 1 in 1.210^28. This is still a significantly better chance than the 1 in 1.110^37 chance of two GUIDs colliding.