Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
@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 -
@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. -
@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. -
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
Related Rants
One of my UUID's contains the string 'f00bar'. Haha. What are the odds?
joke/meme
uuid
coincidence