Use the Uniqid () function in PHP to generate a unique ID

Source: Internet
Author: User
Tags current time end generator md5 rand return string unique id
function Createid ($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 optional. Specify the prefix for the ID. This parameter is useful if two scripts are generating IDs exactly in the same microsecond. More_entropy Optional.   Specify more entropy at the end of the return value. If the prefix parameter is empty, the returned string has 13 strings long. 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 the combined line to generate the program with the remainder), so that the uniqueness of the result is better.   The return value returns a unique identifier in the form of a string. Hint and comment notes: The IDs generated through this function are not optimal because of the system time. To generate an absolutely unique ID, use the MD5 () function (find in the string function Reference)//Mt_rand () to return a random integer using the Mersenne twister algorithm. Mt_rand (Min,max) indicates that if the optional parameter min and Max,mt_rand () are not 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 old libc random number generators have some uncertainties and unknown properties and are slow. The rand () function of PHP uses the libc random number generator by default. The Mt_rand () function is used informally to replace it. The function uses the known characteristics of the Mersenne twister as a random number generator, and it can produce a random numerical velocity of four times times faster than the rand () provided by LIBC.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.