22

One of my UUID's contains the string 'f00bar'. Haha. What are the odds?

Comments
  • 0
    So cool!
  • 1
    Waiting for someone to post the odds. Where are you my Einstein?
  • 11
    @v-vp

    Keep in mind that I am the worst person to find for such a task but I was bored so I did it anyway...

    Considering you want it to be without "-" in between the word:
    There are 3+7=10 possibilities to have it exactly once, 3*7+1=22 to have it twice and even 1 possibility to have it three times! This makes a total of 33 possibilities.
    A UUID consists of 128 bits of which, assuming you use version 4, 6 of the bits are always the same, leaving us with 122 bits.

    As a result, the probability to have _at least one_ "f00bar" in a version 4 UUID is 33/(2^122) which equals approximately 6.21 * 10^-36 or about 6.21 * 10^-34%.

    So that's 0.000000000000000000000000000000000621% if I'm not wrong
  • 2
    @EaZyCode I won't even bother double checking it 😂. I'll take your calculation.
  • 2
    Bro, u are reading your uuid !
    U need vacatation !
  • 0
    @EaZyCode sorry if this seems obvious but could you please elaborate on how you made those calculations. My understanding of uuids means that there are only 3 possible n-grams if the word is without "-"

    Also aren't the odds defined by where its possible to happen rather than the entire domain of all possibilities, i.e the full 128 bit uuid shouldn't be taken into account because the string isn't possible in all places.
  • 0
    @cmarshall10450
    A UUID has the format of
    xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
    Where 4 is always 4 and y has the two top bits set (only values from 8-b), so that's 128-6=122 changeable bits.

    Now, since "f00bar" has a length of 6, I searched where it could fit:
    In the first 8 x's, there are 3 possibilities, offset 0, 1 and 2 (meaning it can be moved to the right by 0, 1 or 2 characters, like so: f00barxx-..., xf00barx-... and xxf00bar-...).
    The middle parts are only 4 characters long, so don't bother checking them.
    The last 12 x's have 7 possibilities, offset 0-6 (same thing again). That's 3+7=10 where exactly one occurrence is possible.

    For the combinations where we have f00bar twice in one UUID, simply multiply 3 by 7, that's just switching all the offsets from before. Now, since f00bar is 6 characters long it fits perfectly into the last 12 x's twice, so that's +1. We have 3*7+1=22.
  • 0
    Oopsie, now I found a mistake!
    There are three possibilities where "f00bar" fits 3 times:
    It fits exactly twice into the last 12 x's and has also the three possibilities in the first 8 x's.
    f00barxx-xxxx-4xxx-yxxx-f00barf00bar and that first part can be moved to the right twice.
    So that's a total of 35, not 33.

    Now the odds are defined by (sorry, I don't know the English terms for that) the combinations where it happens divided by the amount of all combinations.
    The amount of all combinations is 2^122 and, as I just found out, we have 35 combinations where f00bar appears at least once.

    That makes it to be 35/(2^122) which is about 6.58 * 10^-36. I am not going to write those numbers out again, just replace the 6.21 from my previous comment with 6.58.

    But as I already mentioned, I am not very good at this part of mathematics sooo... I could be wrong by a lot
  • 1
  • 0
    @devapsarl You bet I do. I'm overworked.
Add Comment