要使用哪个 UUID 版本? [英] Which UUID version to use?

查看:66
本文介绍了要使用哪个 UUID 版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您应该使用哪个版本的 UUID?我看到很多帖子都解释了每个版本的含义,但我无法弄清楚什么最适合什么应用程序.

Which version of the UUID should you use? I saw a lot of threads explaining what each version entails, but I am having trouble figuring out what's best for what applications.

推荐答案

生成 UUID 有两种不同的方式.

There are two different ways of generating a UUID.

如果您只需要唯一 ID,则需要版本 1 或版本 4.

If you just need a unique ID, you want a version 1 or version 4.

  • 版本 1:这会根据网卡 MAC 地址和计时器生成唯一 ID.这些 ID 很容易预测(给定一个,我可能会猜到另一个)并且可以追溯到您的网卡.不建议创建这些.

  • Version 1: This generates a unique ID based on a network card MAC address and a timer. These IDs are easy to predict (given one, I might be able to guess another one) and can be traced back to your network card. It's not recommended to create these.

第 4 版:这些是从随机(或伪随机)数字生成的.如果您只需要生成一个 UUID,这可能就是您想要的.

Version 4: These are generated from random (or pseudo-random) numbers. If you just need to generate a UUID, this is probably what you want.

如果您需要始终从给定名称生成相同的 UUID,则需要版本 3 或版本 5.

If you need to always generate the same UUID from a given name, you want a version 3 or version 5.

  • 版本 3:这会根据命名空间和名称的 MD5 哈希生成唯一 ID.如果您需要向后兼容(与另一个从名称生成 UUID 的系统),请使用它.

  • Version 3: This generates a unique ID from an MD5 hash of a namespace and name. If you need backwards compatibility (with another system that generates UUIDs from names), use this.

版本 5:这会根据命名空间和名称的 SHA-1 哈希生成唯一 ID.这是首选版本.

Version 5: This generates a unique ID from an SHA-1 hash of a namespace and name. This is the preferred version.

这篇关于要使用哪个 UUID 版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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