Generate unique serial number method collation

Source: Internet
Author: User

These methods are only thought of in peacetime projects, and we hope to collect better methods.

One, time do prefix + random number guarantee only

Use 4 digits to date 0610 + milliseconds to do number 19 + with a digital English array "1-9a-za-z" to extract several to supplement

Generate this: 061019A8DEC2

Second, the current time to replace the corresponding string

Char[] Letters = {' A ', ' C ', ' 1 ', ' 2 ', ' 3 ', ' 4 ', ' A ', ' e ', ' f ', ' Z '}; Here, according to your needs, initialize different characters
String tstr = string.valueof (System.currenttimemillis ());
* * Because the TSTR character is only ' 0 '-' 9 ', we can see it as an index into the letters to find the corresponding character, which is equivalent to "permutation", so it will not repeat. * *
System.out.println (TSTR);
StringBuilder sb = new StringBuilder ();
for (int i=1;i<tstr.length (); i++)
{
sb.append (Letters[tstr.charat (i)-' 0 ']);
System.out.println (Sb.tostring ());




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.