NSUUID 复制机会来自不同的设备. [英] NSUUID duplication chance form different device.

查看:29
本文介绍了NSUUID 复制机会来自不同的设备.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在安装应用程序时为设备生成唯一 ID,并将此值存储在设备上,然后需要使用此 UUID 与服务器通信.而且似乎 NSSUUD 适合情况,但我很困惑是否有可能从多个设备复制 UUID.我已经找到了答案 https://stackoverflow.com/a/6963990/1573209,其中描述了版本 1 类型使用 MAC 地址和 60 位时钟来生成 UUID,因此重复的机会可以忽略不计.Version4 使用一些固定数字和一些随机数来生成 UUID,而 docNSUUID 创建的 UUID 符合 RFC 4122 第 4 版,并使用随机字节创建

I need to generate Unique ID for the device when the application installed, and store this value on the device, then need to communicate with server using this UUID. And it seems NSSUUD suit for the sitiation, but I am confused is there any chance of duplication of the UUID from multiple device. I already found the answer https://stackoverflow.com/a/6963990/1573209 where it describe that the version 1 type uses MAC address and 60 bit clock to generate UUID, so the duplication chance is negligible. Where as the Version4 uses some fixed number and some random number to generate the UUID, and the doc says that UUIDs created by NSUUID conform to RFC 4122 version 4 and are created with random bytes

这是否意味着重复的机会更高?.那么我如何使用版本 1 类型的 UUID 生成器,我看不到它的任何文档.

Does that mean the chance of duplication higher?. Then how can I use version 1 type of UUID generator, I cant see any documentation for it.

推荐答案

你可以看看这个 RFC 4122.符合 RFC 4122 的 UUID 在给定的空间和时间实际上是唯一的.您还可以查看重复的随机 UUID 概率.

You can have look at this RFC 4122. UUID conforming to RFC 4122 are practically unique in given space and time. You can also see Random UUID probability of duplicates.

在总共 128 位中,两位表示 RFC 4122(Leach-Salz")UUID,四位表示版本(0100 表示随机生成"),因此随机生成的 UUID 有 122 个随机位.可以使用概率论(生日问题)计算两个这样的 UUID 具有相同值的机会.计算出 n 个 UUID 后发生意外碰撞的概率,其中 x = 122 发现非常接近于零

Out of a total of 128 bits, two bits indicate an RFC 4122 ("Leach-Salz") UUID and four bits the version (0100 indicating "randomly generated"), so randomly generated UUIDs have 122 random bits. The chance of two such UUIDs having the same value can be calculated using probability theory (birthday problem). Probabilities of an accidental clash after calculating n UUIDs, with x = 122 is found to be very close to zero

对于 n=2^36,即 68,719,476,736 的碰撞概率为 0.0000000000000004.对于较小的 n 值,该值将更小,并且随着生成更多 UUID 的概率增加.在上面的估计中,n 代表生成的 UUID 的数量.

For n=2^36 which is 68,719,476,736 probability of collision is found to be 0.0000000000000004. For lesser value of n, this value will be even less and probability increases as more UUID's are generated. In above estimation n represents number of UUID's generated.

这篇关于NSUUID 复制机会来自不同的设备.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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