问题
If I have two UUIDs, is there a "safe" method to generate a third composite UUID. That is to some statistical definition of the word unique. So I'm looking for function f below in
UUID generatedUUID = f(UUID a, UUID b)
XOR?
回答1:
Depending on where you're getting the two UUIDs from, UUID V3/V5 may be applicable, and any decent library should have functions to generate those. Even if they're not quite right logically, you may be able to abuse them for that purpose anyway. You'd have to explain why you're trying to combine two UUIDs in the first place for us to be sure.
In any case, do not use a simple XOR (or other generic operation) on two UUID values because that will likely mess up the version/variant fields, giving you a result that is not itself a valid UUID or, worse, collides with a valid UUID that should not otherwise be collidible.
来源:https://stackoverflow.com/questions/33866477/generate-composite-uuid-from-two-uuids