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)