UUID (Universally unique Identifier), GUIDs are expected to generate a unique identification code throughout the space-time range, which is necessary in a distributed computing environment. However, if you just want to create a "local unique identification code" in a limited local environment, using the UUID is overkill, this "local unique identifier", which I call LUID (local unique Identifier)
For example, I am using PHP to develop the website program, in order to avoid the user simultaneously open the same page multiple times cause the session name conflict problem, I hope to save the session is not $_session[' param '], but $_session[$luid [' param '], Another way to pass the $LUID value is to ensure that the ' param ' parameter is not overwritten. Find out the other people's solution, are generated UUID, and the algorithm to generate UUID voluminous hundreds of rows. I consider that because it is in the session space, is a limited environment, its uniqueness intensity does not have to be too high, as long as in the same session of the lifetime of the only can be, so there is the following code:
Copy CodeThe code is as follows:
/**
* Returns a unique string that is unique in the local system.
* Returns a 32-character string in the form of ' 7dac352074f221f3edc74d265c65a636 ', or ' D198D8FC56FFED627F3F8313D6F06ACF '
*/
function LUID () {
Return MD5 (Microtime ());
}
In fact, one line. Return MD5 (Microtime ());
According to the reason Microtime () The string returned is already unique, I measured, even if the microtime (), the return value is more than 100us difference, and the user clicks, and on the network to pass the server processing more than dozens of Ms interval. Adding MD5 just makes the results messy.
http://www.bkjia.com/PHPjc/326068.html www.bkjia.com true http://www.bkjia.com/PHPjc/326068.html techarticle UUID (Universally unique Identifier), GUIDs are expected to generate unique identifiers throughout the space-time range, which is necessary in a distributed computing environment. However, if you just want to be in a restricted ...