import java.util.UUID;
public class RandomStringUUID {
public static void main(String[] args) {
UUID uuid = UUID.randomUUID();
String randomUUIDString = uuid.toString();
System.out.println("Random UUID String = " + randomUUIDString);
System.out.println("UUID version = " + uuid.version());
System.out.println("UUID variant = " + uuid.variant());
}
}
Guid guid = Guid.NewGuid();
string guidString = guid.ToString();
#include <rpc.h>
#pragma comment(lib, "Rpcrt4.lib")
...
UUID uuid;
::ZeroMemory(&uuid, sizeof(UUID));
// UuidFromString() function
::UuidCreate(&uuid);
// To convert uuid to string, use the UuidToString() function
WCHAR* wszUuid = NULL;
::UuidToStringW(&uuid, &wszUuid);
if(wszUuid != NULL)
{
::RpcStringFree(&wszUuid);
wszUuid = NULL;
}
NSString *UUID = [[NSUUID UUID] UUIDString];
A Globally Unique Identifier (GUID, /ˈɡwɪd/or /ˈɡuːɪd/) is a unique reference number used as an identifier in computer software. The term GUID typically refers to various implementations of the universally unique identifier (UUID) standard.
GUIDs are usually stored as 128-bit values, and are commonly displayed as 32 hexadecimal digits with groups separated by hyphens, such as {21EC2020-3AEA-4069-A2DD-08002B30309D}.
GUIDs generated from random numbers sometimes contain 6 fixed bits saying they are random and 122 random bits; the total number of unique such GUIDs is 2122 (approximately 5.3×1036). This number is so large that the probability of the same number being generated randomly twice is negligible; however other GUID versions have different uniqueness properties and probabilities, ranging from guaranteed uniqueness to likely non-uniqueness.
Assuming uniform probability for simplicity, the probability of one duplicate would be about 50% if every person on earth as of 2014 owned 600 million GUIDs.