本文介绍了Android和Java Uuid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的应用程序生成一个uuid我尝试了许多东西,如wifi mac地址,获取android id,序列号,从设备创建伪uuid
android.os.Build 属性。



我也知道java本身有Uuid创建者类
java.util.UUID / p>

通过浏览几篇文章和博客,我对此并不感到困惑。我想知道,如果两个android设备正在使用这个java类( java.util.UUID )创建uuid将会是唯一的还是有复制的机会? p>

在某些设备中,我无法使用 android.os.Build.SERIAL 找到序列号。是否有替代方法获取设备的序列号

解决方案

假设您正在使用java.util.UUID的 randomUUID()函数有一个理论上的复制机会,但它是非常遥远的。生成的ID是 version-4 ids,它们随机设置了122位。这意味着有5.32 x 10 ^^ 36个可能的值。对于一些观点,如果你有十亿个设备,每秒产生十亿个ID,那么他们将完成大约1680亿年的时间(约10倍的宇宙年龄)。



所以,是的,复制是可能的,但是(假设Java正在使用高质量随机数生成器),其实际发生的几率是非常遥远的,没有意义。


I want to generate a uuid for my app i tried many things like wifi mac address , getting android id, serial number , creating pseudo uuid from device android.os.Build properties .

i also came to know that java itself got Uuid creator class java.util.UUID

by going through several articles and blogs i am little confused about this . i want to know that if two android device are creating uuid using this java class(java.util.UUID) will that be unique or is there any chance for duplication?

Also in some devices i was not able to find serial number using android.os.Build.SERIAL . is there alternative way to get serial number of device

解决方案

Assuming you're using the java.util.UUID's randomUUID() function there's a theoretical chance of duplication, but it's incredibly remote. The ids generated are RFC4122 version-4 ids, which have 122 bits randomly set. That means there are 5.32 x 10^^36 possible values. For some perspective on that, if you had a billion devices, each generating a billion IDs per second, it would take roughly 168 billion years for them to finish (~10X the age of the universe).

So, yes, duplication is possible, but (assuming Java is using a high quality random number generator), the odds of it actually happening are so remote as to be meaningless.

这篇关于Android和Java Uuid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 14:16