mathwolfram-mathematicamathematical-optimization

How to generate a unique GUID from two unique GUIDs, which are order-insignificant


I have an application whereby users have their own IDs. The IDs are unique. The IDs are GUIDs, so they include letters and numbers. I want a formulae whereby if I have both IDs I can find their combined GUID, regardless of which order I use them in. These GUIDs are 16 digits long, for the example below I will pretend they are 4.

user A: x43y user B: f29a

If I use formula X which takes two arguments: X(a,b) I want the produced code to give the same result regardless whether a = UserA or UserB's GUID. I do not require a method to find either users IDs, given one, from this formulae - ie it is a one way method.

Thank you for any answers or direction


Solution

  • Sort the GUIDs lexicographically and append the second to the first. The result is unique, and has all the other characteristics you've asked for.

    Can you compress it (I know you wrote shorten but bear with me) down to 16 characters ? No you can't; not, that is, if you want to be able to decompress it again and recover the original bits. (You've written that you don't need to be able to recover the original GUIDs, skip the next paragraph if you want to.)

    A GUID is, essentially, a random sequence of 128 bits. Random sequences can't, by definition, be compressed. If a sequence of 128 bits is compressible it can't be random, there would have to be some algorithm for inflating the compressed version back to 128 bits. I know that since GUIDs are generated algorithmically they're not truly random. However, in practice there is almost no point in regarding them as anything other than truly random; I certainly don't think you should waste your time trying to compress them.

    Given that the total population of possible GUIDs is large, you might be satisfied by a method which takes the first half of each individual GUID and assembles a pseudo-GUID from them. Depending on how many GUIDs your system is likely to be working with, and your appetite for risk, this might satisfy your practical needs.