• Wody (unregistered) in reply to GettinSadda
    GettinSadda:
    The number of random GUIDs (using version 4 which is most common now) there are 2^122 or about 5.3 * 10^36 values.

    To put this into perspective the universe is about 4.6 * 10^17 seconds old, so if a device started calculating 11 billion billion GUIDs a second at the big bang, it would be running out soon.

    it's going to run out on the 21st of december this year. Will something happen? Maybe, maybe not. Who knows?

  • ThomasX (unregistered)

    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.

  • Hegel (unregistered)

    The method should be refactored to

    private Guid DifferentGuid(params Guid[] guids, IGuidGenerator generator)

    just in case the built-in GUID generator implementation does not generate unique-enough GUIDs.

  • (cs) in reply to Remy Porter
    Remy Porter:
    It's hard to work HTML comments into CodeSODs. It's more of a feature article thing. Also, the editor we use for posting articles will eat them if anybody uses IE to edit an article. *ahem*
    And why no unicorns?!
  • Harrow (unregistered) in reply to Zylon
    Zylon:
    Harrow:
    For starters, if my MAC address is compromised I cannot change it.
    Ahem.
    Good point. But what are the PHB's at MS worried about exposing, the spoofed MAC or the hardware MAC on the NIC?

    -Harrow.

  • consequat (unregistered) in reply to Andrew Stein
    Andrew Stein:
    I hope that none of you ever have the joy of generating GUIDs in parallel using Oracle on AIX. See Andy Hogg's excellent analysis at http://sqlfascination.com/2012/01/22/oracle-duplicate-guid-values-being-returned-from-sys_guid-when-run-in-parallel/

    That's why smart people run away from crappy systems like Oracle and Java and similar undocumented crap like Unix.

  • consequat (unregistered) in reply to MightyM
    MightyM:
    She sapped me of my precious bodily guids:
    GUIDs take up too much space. Use integers:

    Guid.NewGuid().ToString().GetHashCode()

    Wow, just wow.

    (Obligatory Eric Lippert link: http://blogs.msdn.com/b/ericlippert/archive/2010/03/22/socks-birthdays-and-hash-collisions.aspx)

    I know - a day won't pass that I don't stumble upon a dumbass.

  • (cs)

    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.

  • jay (unregistered) in reply to ORly?
    ORly?:
    spike:
    TRWTF is that this code was written in the first place, it stinks of premature protection.
    Premature protection? Is that what you call it now? Is that your lofty-sounding excuse for not testing anything until it breaks in production?

    "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.

  • (cs) in reply to jay
    jay:
    ORly?:
    spike:
    TRWTF is that this code was written in the first place, it stinks of premature protection.
    Premature protection? Is that what you call it now? Is that your lofty-sounding excuse for not testing anything until it breaks in production?

    "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.

    Or wearing a rubber with the rest of your daily attire in the event that it might be useful for once.

  • Luc (unregistered)

    While (comments.Next) If Comment.equals ('Frist') DifferentComment('Secunt')

  • (cs) in reply to Cbuttius
    Cbuttius:
    A bit like having the same primary key but for different database tables..

    Man, you have that problem too? How do you take care of it?

  • (cs) in reply to Some Jerk
    Some Jerk:
    Can you force the insert to retry if it fails?

    Thankfully, this is illegal in enlightened states.

  • Neil (unregistered) in reply to Some Jerk
    Some Jerk (unregistered):
    I'm no Einstein, but isn't time constant?
    Time is an illusion. Lunchtime doubly so.

    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?

  • (cs)

    All the suggestions as to how to do it "safer" presented above are silly. It's obvious how it should be done.

    1. Register a domain, call it "tehguids.net"

    2. Every enterprise that generates guids gets their own server on a subdomain there, serving a linked page of guids it generated since its inception.

    3. 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.

  • Martin (unregistered)

    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...

  • Typhin (unregistered)

    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.

  • TortoiseWrath (unregistered)

    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.

Leave a comment on “GUGUID”

Log In or post as a guest

Replying to comment #:

« Return to Article