Theoretically, I don't think this method will return repeated UUIDs, even from different devices.
Let's check the documentation of android: http://developer.android.com/reference/java/util/UUID.html. It says "Generates a variant 2, version 4 (randomly generated number) UUID as per RFC 4122."
Even in JDK documentation http://docs.oracle.com/javase/6/docs/api/java/util/UUID.html , it says they are implementing RFC 4122.
And in RFC 4122, http://www.ietf.org/rfc/rfc4122.txt, it says "A UUID is 128 bits long, and can guarantee uniqueness across space and time."
Wikipedia also calculates the probability of duplicates of RandomUUID: http://en.wikipedia.org/wiki/Universally_unique_identifier#Random_UUID_probability_of_duplicates
There is a guy here (http://www.coderanch.com/t/385404/java/java/UUID-Uniqueness-JVMs) states that "We (i.e. my team at work) have been using the Java Util UUID class for UUIDs across JVMs."
However, I still can see a lot of worries that the Java randomUUID will not be unique.
First of all, let us check the wikipedia:http://en.wikipedia.org/wiki/Universally_unique_identifier. It says java is not using MAC address for generating UUID "due to lack of means to access MAC addresses using pure Java before version 6". It also gives opensource UUID generation tools as http://johannburkard.de/software/uuid/ and https://github.com/cowtowncoder/java-uuid-generator. Not sure not using MAC address will make them not unique.
Some people here (http://www.coderanch.com/t/385404/java/java/UUID-Uniqueness-JVMs) also say they are using a central control to generate UUID.
This link(http://stackoverflow.com/questions/2513573/how-good-is-javas-uuid-randomuuid ) says "implementation to contain subtle bugs that ruin all this (see OpenSSH key generation bug)".
This link(http://stackoverflow.com/questions/6505837/is-oracles-sys-guid-uuid-rfc-4122-compliant) says "SYS_GUID is Oracle's equivalent of UUID. It is globally unique. However, it is not compliant to RFC 4122".
Anyway, I do not find any evidence that says UUID.randomUUID() will repeat, even from different machines. As it says here (http://stackoverflow.com/questions/2513573/how-good-is-javas-uuid-randomuuid), "I don't think there's any concrete reason to worry about Java UUIDs's randomness."
However, if we are building very critical distributed applications with a lot of data, maybe, we can consider using MAC address algorithm, or using central UUID generator.
Let's check the documentation of android: http://developer.android.com/reference/java/util/UUID.html. It says "Generates a variant 2, version 4 (randomly generated number) UUID as per RFC 4122."
Even in JDK documentation http://docs.oracle.com/javase/6/docs/api/java/util/UUID.html , it says they are implementing RFC 4122.
And in RFC 4122, http://www.ietf.org/rfc/rfc4122.txt, it says "A UUID is 128 bits long, and can guarantee uniqueness across space and time."
Wikipedia also calculates the probability of duplicates of RandomUUID: http://en.wikipedia.org/wiki/Universally_unique_identifier#Random_UUID_probability_of_duplicates
There is a guy here (http://www.coderanch.com/t/385404/java/java/UUID-Uniqueness-JVMs) states that "We (i.e. my team at work) have been using the Java Util UUID class for UUIDs across JVMs."
However, I still can see a lot of worries that the Java randomUUID will not be unique.
First of all, let us check the wikipedia:http://en.wikipedia.org/wiki/Universally_unique_identifier. It says java is not using MAC address for generating UUID "due to lack of means to access MAC addresses using pure Java before version 6". It also gives opensource UUID generation tools as http://johannburkard.de/software/uuid/ and https://github.com/cowtowncoder/java-uuid-generator. Not sure not using MAC address will make them not unique.
Some people here (http://www.coderanch.com/t/385404/java/java/UUID-Uniqueness-JVMs) also say they are using a central control to generate UUID.
This link(http://stackoverflow.com/questions/2513573/how-good-is-javas-uuid-randomuuid ) says "implementation to contain subtle bugs that ruin all this (see OpenSSH key generation bug)".
This link(http://stackoverflow.com/questions/6505837/is-oracles-sys-guid-uuid-rfc-4122-compliant) says "SYS_GUID is Oracle's equivalent of UUID. It is globally unique. However, it is not compliant to RFC 4122".
Anyway, I do not find any evidence that says UUID.randomUUID() will repeat, even from different machines. As it says here (http://stackoverflow.com/questions/2513573/how-good-is-javas-uuid-randomuuid), "I don't think there's any concrete reason to worry about Java UUIDs's randomness."
However, if we are building very critical distributed applications with a lot of data, maybe, we can consider using MAC address algorithm, or using central UUID generator.
相关推荐
利用UUID生成完全不... UUID uuid = UUID.randomUUID(); tv.setText(uuid.toString()); } @Override public void onClick(View v) { UUID uuid = UUID.randomUUID(); tv.setText(uuid.toString()); } }
UUID uuid = UUID.randomUUID(); ``` 然后,你可以用它来进行比较或者转换成其他格式: ```java // 比较两个UUID boolean isEqual = uuid.equals(anotherUuid); // 转换成16进制字符串 String hexString = uuid....
UUID uuid = UUID.randomUUID(); ``` ##### 实现代码示例 ```java package com.mytest; import java.util.UUID; public class UTest { public static void main(String[] args) { UUID uuid = UUID....
《JavaScript中的UUID生成:深入理解Math.uuid.js》 在JavaScript编程中,UUID(Universally Unique Identifier)是一种广泛应用的全局唯一标识符,它主要用于创建对象的唯一ID,尤其是在分布式环境中。Math.uuid....
"自动生成主键uuid.zip"这个压缩包文件很可能是包含了一个Java程序示例,用于演示如何生成这样的32位ID。 在Java中,生成UUID主要通过`java.util.UUID`类提供的静态方法。`UUID.randomUUID()`是生成一个随机的UUID...
d2 = java.util.UUID.randomUUID(); bjson.put("b1", d2.toString()); d2 = java.util.UUID.randomUUID(); bjson.put("b2", d2.toString()); d2 = java.util.UUID.randomUUID(); bjson.put("b3", d2.toString...
官方文档 安卓Q中Google彻底禁止第三发app获取IMEI,获取...var uniqueID = UUID.randomUUID().toString() 2.Java写法 String uniqueID = UUID.randomUUID().toString(); 2. 使用硬件信息拼接生成一个ID public stati
运行上述`Uuid16.java`程序,将输出两个UUID,第一个是通过`UUID.randomUUID()`生成的,可能是版本4,因为版本1的生成需要额外的信息,如MAC地址,Java默认不会提供。第二个是通过构造函数生成的,模拟了UUID1的生成...
d2 = java.util.UUID.randomUUID(); bjson.put("b1", d2.toString()); d2 = java.util.UUID.randomUUID(); bjson.put("b2", d2.toString()); d2 = java.util.UUID.randomUUID(); bjson.put("b3", d2.toString...
UUID.js, 用于JavaScript的符合RFC的UUID生成器 电子邮件名称UUID.js - 适用于JavaScript的兼容UUID生成器概要<!-- HTML5 -->[removed][removed]&
uuid 默认生成带横线的 uuid -s 生成不带横线的uuid
标题“uuid.rar_C获得UUID_UUID C_c生成uuid_c语言生成uuid_uuid”表明这是一个关于使用C语言实现UUID生成的资源包。这个压缩包可能包含了一个C语言编写的程序或库,可以用来在Windows平台上(通过VC6编译器)生成...
在 Java 中,我们可以使用 UUID.randomUUID() 方法来生成一个随机的 UUID。同时,我们也可以使用 UUID.nameUUIDFromBytes() 方法来生成一个基于名称的 UUID。 关于 UUID 的校验,Java 提供了多种方法来实现。我们...
myEntity.setUuid(UUID.randomUUID().toString()); ``` 5. 序列化与反序列化:根据需要,可以将生成的`MyEntity`对象序列化为二进制数据,也可以从二进制数据反序列化回`MyEntity`对象。 在实际应用中,PB生成UUID...
标题中的"ucrt.lib uuid.lib kernel32.lib"是一组重要的Windows系统库文件,它们在Windows应用程序开发中扮演着至关重要的角色。这些库文件提供了大量的API函数,供开发者调用以实现各种操作系统级别的功能。 首先...
UUID.js-JavaScript的RFC兼容UUID生成器 概要 <!-- HTML5 --> < script src =" src/uuid.js " > </ script > < script > var uuid = UUID . generate ( ) ; </ script > // Node.js...
在给定的"uuid.rar_uuid"压缩包中,包含两个文件:uuid.h和uuid.c。这两个文件分别代表头文件和源代码文件,通常在C语言编程环境中使用,用于实现UUID的相关功能。 1. `uuid.h`:这是一个头文件,通常包含了UUID库...
UUID uuid = UUID.randomUUID(); // 生成UUID String str = uuid.toString(); // 将UUID转换为字符串 System.out.println(str.replace("-", "")); // 输出去除横线的UUID } } ``` 2. **其他语言示例**:除了...
UUID uniqueId = UUID.randomUUID(); String uuidString = uniqueId.toString(); ``` 生成的UUID字符串通常形如“550e8400-e29b-41d4-a716-446655440000”,由五组32位的十六进制数字组成,中间用短横线分隔。 ...
在给定的“UUID.rar”压缩包中,我们看到涉及UUID的一些关键元素,包括C语言实现、UUID加密以及在Windows CE(Wince)系统中的应用。 1. **UUID的基础概念**: - UUID是一种128位的数字,通常以16进制表示,分为5...