Read Catalogue
- 1.UUID Introduction
- 2.UUID composition
- 3. Project Combat
Back to top of 1. Introduction to UUID
UUID meaning is a universal unique identifier (universally unique Identifier), which is a software construction standard and is also open Software Foundation, OSF
Organizations are used in a distributed computing environment (distributed Computing Environment, DCE) as part of the domain.
The purpose of the UUID is to allow all elements in a distributed system to have unique identification information without the need to specify the information through the central control terminal. In this way, everyone can create a UUID that does not clash with others.
In such a case, there is no need to consider the name duplication problem when the database is established. Currently the most widely used UUID is Microsoft's globally Unique Identifiers (GUIDs), while other important applications,
Linux ext2/ext3 file system, LUKS encryption partition, GNOME, KDE, Mac OS X, etc.
Back to top of 2. UUID composition
The UUID guarantees that all machines in the same time and space are unique. Typically, the platform provides the generated APIs. Based on standard calculations developed by the Open Software Foundation (OSF), Ethernet card addresses, nanosecond-seconds, chip ID codes, and many possible numbers are used
The UUID is composed of the following parts:
(1) The current date and time, the first part of the UUID is related to the time, if you generate a UUID after a few seconds to generate a UUID, then the first part is different, the rest is the same.
(2) clock sequence.
(3) Globally unique IEEE machine identification number, if there is a network card, from the network card MAC address obtained, no network card is obtained in other ways.
The only drawback to the UUID is that the resulting string will be longer. The most common use of UUID for this standard is the GUID of Microsoft (Globals Unique Identifiers). In ColdFusion, the UUID can be easily generated with the Createuuid () function,
The format is: xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxxxxxx (8-4-4-16), where each x is a hexadecimal number in the range of 0-9 or a-f. The standard UUID format is: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx (8-4-4-4-12);
Back to top 3. Project Combat
UUID as the database data table primary key is a good choice to ensure that each generated UUID is unique.
A. Generating UUID
Need to use Java to bring the JDk;
Import java.util.uuid;public static void Main (string[] args) {for (int i=0;i<10;i++) {String UUID = Uuid.randomuuid (). ToString (). ReplaceAll ("-", "" "); SYSTEM.OUT.PRINTLN (UUID);}}
B. Generating a specified number of UUID
/** * Gets the specified number of UUID * @param number int need to get UUID count * @return string[] UUID array */public static string[] Getuuid (int number) { if (number < 1) {return null;} string[] Retarray = new String[number]; for (int i=0;i<number;i++) {Retarray[i] = Getuuid ();} return retarray; }/** * Gets a UUID * @return string UUID */public static string Getuuid () {String UUID = Uuid.randomuuid (). toString ();//Remove " -"Sign return Uuid.replaceall ("-"," "");}
Java Generation UUID