A software installation serial number of 20 characters is randomly generated.

Source: Internet
Author: User

Import java. util .*;
Public class gensn
{
Random objrandom;
Public gensn ()
{
Long seed = calendar. getinstance (). gettimeinmillis ();
Objrandom = new random (SEED );
}
Private char genchar ()
{
// The characters to be generated include 26 letters, 10 digits, and 36 characters in total
Int irand = objrandom. nextint (36 );
// Set 0 ~ A random number between 9, mapped to the corresponding number
If (irand <= 9)
Return (char) (irand + 48 );
Else
Return (char) (irand + 55 );
}
Public static void main (string ARGs [])
{
System. Out. Print ("serial number :");
Gensn OBJ = new gensn ();
For (INT I = 1; I <24; I ++)
{
If (I % 6! = 0)
System. Out. Print (obj. genchar ());
Else
System. Out. Print ("-");
}
System. Out. println ();
}
}

Note: Numbers 0 ~ The ASCII code of 9 is from 48 ~ 57. The ASCII code of uppercase letters ranges from 65 ~ 90.

Related Article

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.