从两个 UUID 生成复合 UUID [英] Generate composite UUID from two UUIDs

查看:71
本文介绍了从两个 UUID 生成复合 UUID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有两个 UUID,是否有安全"的方法来生成第三个复合 UUID.那就是对unique这个词的一些统计定义.所以我在

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)

异或?

推荐答案

根据您从何处获取两个 UUID,UUID V3/V5 可能适用,并且任何合适的库都应该具有生成这些的函数.即使它们在逻辑上不太正确,您仍然可以为此目的滥用它们.您首先必须解释为什么要尝试组合两个 UUID,以便我们确定.

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.

在任何情况下,不要对两个 UUID 值使用简单的 XOR(或其他通用操作),因为这可能会弄乱版本/变体字段,给你一个不是它本身的结果一个有效的 UUID,或者更糟的是,与一个不应该被碰撞的有效 UUID 发生冲突.

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.

这篇关于从两个 UUID 生成复合 UUID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆