in the case of not query the database, each member login in generates a digital letter combinations not duplicate membership number.

rendering is as follows:

when we will be a large number of data, and the number of the digits are the restrictions, such as license plate number five, 10 a certificate number, order number, short url, etc., we can use the 36 in digit hexadecimal calculated not repeat number.

                                                                                                                                                              View the demo download the source code

we will 0 - Z (0123456789 abcdefghijklmnopqrstuvwxyz) represent the number 0-35, such as the letter "Z" stands for 35. So I want to get a number 5, 5 of the maximum amount of information is 36 square, 36 ^ 5=60466176, namely the five biggest number of decimal number: 60466176.

in this paper in order to making a presentation, we assume that a club issued a group of 10 member card, membership number by three city number + 2 + 5 card number coding check code. Number in the city area code, said such as 755 on behalf of shenzhen, five card number is composed of 36 card number into the system, behind the two check code is generated by a certain algorithm, check code can be used to verify the legitimacy of the card number. In this way, we generate 10 card number is equal to the maximum to meet membership card number of more than 6000, and is not to repeat the only card number.


we use PHP to hexadecimal conversion, decimal turned 36 hexadecimal.

The class Code {//password dictionaryPrivate $dic=array (0=>'0', 1=>'1', 2=>'2', 3=>'3', 4=>'4', 5=>'5', 6=>'6', 7=>'7', 8=>'8',9=>'9', 10=>'A', 11=>'B', 12=>'C', 13=>'D', 14=>'E', 15=>'F', 16=>'G', 17=>'H',18=>'I', 19=>'J'=20 >'K', 21=>'L', 22=>'M, 23=>'N', 24=>'O', 25=>'P', 26=>'Q',27=>'R', 28=>'S', 29=>'T', 30=>'U', 31=>"V", 32=>'W', 33=>'X', 34=>'Y', 35=>'Z');The public function encodeID ($int, $format=8) {$dics=$this - >Dic.$dnum=36;//hexadecimal number$arr=array ();$loop=true;While ($loop) {$arr=$[] dics [bcmod ($int, $dnum)];$int=bcdiv ($int, $dnum, 0).If ($int=='0') {$loop=false;}}If (count ($arr) <$format)$arr=array_pad ($arr, $format, $dics [0]).Return the implode (' ', array_reverse ($arr));}The public function decodeID ($ids) {$dics=$this - >Dic.$dnum=36;//hexadecimal number//key exchange$dedic=array_flip ($dics);//to zero$id=ltrim ($ids, $dics [0]).//reverse$id=strrev ($id);$v=0;For ($I=0, $j=strlen ($id); $I <$j; $i++) {$v=bcadd (bcmul ($dedic [$id {$I}], bcpow ($dnum, $I, 0), 0), $v, 0);}Return the $v.}} 

we define Code class, first define the password dictionary, namely 0 - Z corresponding numerical values, methods encodeID ($int, $format) parameter $int represent Numbers, $format said digit length, for example encodeID (123456789, 5) to convert the number 123456789 to 36 hexadecimal number 5, the method decodeID ($ids) are used to 36 hexadecimal Numbers into decimal number.

we can to generate the code like this:

$code=new code ();$card_no=$code - >EncodeID (888888, 5); 

as above, we can get a five card number, it actually represents a card number is 888888 (6) the membership number, and after the actual transformation is number five: 0 j1vc.

then, we will be number and check code and city, city number is already defined, check code is obtained through a certain algorithm, in this case, we used a simple algorithm: the top three cities number and five card number to md5 encryption, and then take the md5 value of the former two as check code, thus to get the number two at the back of the check code.

$card_pre='755';$card_vc=substr (md5 ($card_pre. $card_no), 0, 2);$card_vc=strtoupper ($card_vc);Echo $card_pre. $card_no. $card_vc; 

in the practical application, can through the database to get the decimal number, ensure the Numbers only, then the code combination, the resulting a membership number 10 don't repeat.

This concludes the body part