36-digit barcode serial number generator [updated]

Source: Internet
Author: User
This Algorithm I have a search on the Internet. For now, I feel that my algorithms are the most suitable.

The most recent case involves bar code printing. The request is a unique sequence. There is a date in the middle, and the last three digits are the serial number. But the number of printed sheets will exceed 999;
Therefore, 26 uppercase letters are required. The requirements are as follows: 999 is a common number (001 ~ 999), then we start to use a hundred letters, that is, the last digit of 999 is a00. At this time, ten digits and single digits cannot use letters (at ordinary times, there will be less than 3600 printed letters, for the convenience of the customer ),
Only after a hundred bytes of Z are used up can ten letters be used up, and only one digit can be used up.

In hexadecimal notation, three digits can represent 36*36*36 = 46656 digits.

Note:
1) it cannot be repeated.
2) The number of numbers should reach 46656
3) efficiency cannot be too low
4) Please test locally without repeated serial numbers

Because Visual Studio is not installed on the home computer, the format is. Private   Readonly   Char [] Char26 {} = New   Char {A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, t, U, V, W, X, Y, Z} ;
Private   Readonly   Char [] Char36 {} = New   Char {0,1,2,3,4,5,6,7,8,9, A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, t, U, V, W, X, Y, Z} ;

Public   String Convertnum ( Int Num)
{
If (Num < 0   | Num > = 46655 )
{
 Throw NewException ("The number entered exceeds the range.");
}
Else   If (Num > = 12959 )
{
String Value = "" ;
Num -= 12959 ;
Char D = Char26 [( Int ) (Num / 1296 )];
Num = Num % 1296 ;
Char T = Char36 [num % 36 ];
Char H = Char36 [( Int ) (Num / 36 )];
Return Value + H + T + D;
}
Else   If (Num > 3599 )
{
  String Value = "" ;
Num -= 3599 ;
  Char T = Char26 [( Int ) (Num / 360 )];
Num = Num % 1296 ;
  Char H = Char36 [num % 36 ];
  Int D = Num % 10 ;
  Return Value + H + T + D;
}
Else   If (Num > = 10 )
{
  String Value = "" ;
Num -= 3599 ;
  Char H = Char36 [( Int ) (Num / 100 )];
Num = Num % 100 ;
  Int T = ( Int ) (Num / 10 );
  Int D = Num % 10 ;
  Return Value + H + T + D;
}
Else
{
 Return "00"+Num;

}
 


}

Not at homeCodeFirst, the pseudo code for testing is provided.
// Define a new list <string> Nums
// I cycles from 0 to 46655
// Enter I to obtain the serial number num
// Whether Nums contains num
// Add num to Nums if it is not included
// Output the duplicate sequence if it contains
// The loop is complete.
// Check whether the number of num in Nums is 46656

Some netizens mentioned when there were 3 letters.
In z99, the last digit is 0a0,
The number after 0a9 is 1a0.
The last digit of za9 is 0b0.

The last digit of zz9 is 00a.

The last digit of 00Z is 01a (please think about why)

The algorithm I have compiled is used in the case. After testing, I can obtain all 46656 numbers. (the code will be released next Friday)
During this period, in order to speed up the operation, I used the table-driven method and achieved better computing efficiency.
In addition, I plan to write a small article about the table-driven method.

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.