PHP generated 12-bit non-repeating number letter combination card number, how to solve

Source: Internet
Author: User
PHP generates 12-bit non-repeating digital letter combination card number
In the case of not querying the database, each member login will generate a digital letter combination of non-repeating membership card number.
------Solution--------------------
The easiest thing to think about is the use of random numbers, but you can't prove that the results of the two times are necessarily different.
MD5 produces a 32-bit result string and has proven that MD5 has a "collision": two different content with the same MD5 value
Also, you cannot prove that the truncated MD5 value has the same uniqueness as the original string.
Therefore, it is more prudent to use time as a parameter.
function foo () {
$o = $last = ";
do {
$last = $o;
Usleep (10);
$t = Explode (' ', Microtime ());
$o = substr (Base_convert (STRTR ($t [0]. $t [1]. $t [1], '. ', '), 10, 36), 0, 12);
}while ($o = = $last);
return $o;
}
Of course, this generation algorithm also has limitations. 12-bit 36 binary number with POW (36, 12) states
Repetition is inevitable when the total amount exceeds the POW (36, 12)
  • 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.