functionCreateid ($prefix= "")
{
$str= MD5(uniqid(Mt_rand(), true));
return$prefix. $str;
}
//
Uniqid (prefix,more_entropy)
The Uniqid () function generates a unique ID based on the current time in microseconds.
prefix is optional. Specify a prefix for the ID. This parameter is useful if two scripts generate IDs exactly in the same microsecond.
More_entropy is optional. Specifies more entropy at the end of the return value.
If the prefix parameter is empty, the returned string has 13 string lengths. If the More_entropy parameter is set to True, it is 23 strings long.
If the More_entropy parameter is set to True, additional entropy is added at the end of the return value (using a combination line with the remainder generator), which results in better uniqueness.
return value
Returns a unique identifier in the form of a string.
Hints and Notes
Note: The ID generated by this function is not optimal due to system time. To generate an absolutely unique ID, use the MD5 () function (find in the string function Reference)
//
Mt_rand () returns a random integer using the Mersenne Twister algorithm.
Mt_rand (Min,max)
Description
If no optional parameter min and Max,mt_rand () are provided, the pseudo-random number between 0 and Rand_max is returned. For example, want a random number between 5 and 15 (including 5 and 15), with Mt_rand (5, 15).
Many of the old libc random number generators have some uncertainties and unknown characteristics and are slow. The rand () function of PHP uses the libc random number generator by default. The Mt_rand () function is informally used to replace it. The function uses the known characteristics of the Mersenne Twister as a random number generator, which can produce random values four times times faster than Rand () provided by LIBC.
Use the Uniqid () function to generate a unique ID in PHP