Php generates 12-digit non-repeated alphanumeric member card numbers

Source: Internet
Author: User
Php generates 12-digit, unique-digit, and alphanumeric member card numbers without querying the database. when each member logs in, a unique membership card number is generated. Share to: more php generate 12-digit non-repeating alphanumeric combination membership card numbers
When you log in without querying the database, each member will generate a membership card number with no duplicate combinations of numbers and letters.

Share: More


------ Solution --------------------
The most easy to think of is the use of random numbers, but you cannot prove that the two results must be different.
MD5 generates a 32-bit result string and has proved that MD5 has a "collision": two different contents have the same MD5 value.
Similarly, you cannot prove that the MD5 value after truncation is the same as that of the original string.
Therefore, it is safer 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. A 12-bit 36-digit number can have a maximum of pow (36, 12) states.
When the total volume exceeds pow (36, 12), repetition is inevitable.

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.