The UUID full name is the universally unique identifier, which is an identifier that can be generated using any computer, without requiring a central database for management, which guarantees that there is little chance of duplication. The range of the UUID is said to assign a UUID to every grain of sand in the world, and there is no repetition.
Recently in the code to change WordPress, need to use UUID. However, there is no function in PHP to generate the UUID, so you have to write one yourself.
if (!function_exists (' Com_create_guid ')) {
function com_create_guid () {return
sprintf ('%04x%04x-%04x-%04x- %04x-%04x%04x%04x ',
mt_rand (0, 0xFFFF), Mt_rand (0, 0xFFFF),
mt_rand (0, 0xFFFF),
mt_rand (0, 0x0fff) | 0 x4000,
mt_rand (0, 0x3fff) | 0x8000,
mt_rand (0, 0xFFFF), Mt_rand (0, 0xFFFF), Mt_rand (0, 0xFFFF)
);
}
}
The above code can generate a UUID version 4. The UUID currently has 5 versions, of which the fourth edition is completely random and easy to generate. And the Com_create_guid, is a function of PHP in Windows, it directly calls the COM CreateGUID function to generate the UUID, but in Linux does not have the corresponding function library, had to write their own. To facilitate use on different platforms, a function with the same name is created. The other code is to generate random numbers.
As for usage, call Com_create_guid () directly.