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.