Java randomly generated strings (character randomly generated classes generate random character combinations)

Source: Internet
Author: User
Tags addall stringbuffer

Original: http://www.jb51.net/article/45006.htm

 PackageP2p_web;Importjava.util.ArrayList;Importjava.util.Arrays;ImportJava.util.Random;/*** Character randomly generated class *@authorASUS **/ Public classPassWord {/*** Password Type enumeration *@authorASUS*/  Public Static enumTYPE {/*** Character Type*/Letter ,/*** Uppercase and lowercase character type*/Capital ,/*** Digital Type*/Number ,/*** Symbol Type*/Sign ,/*** Large + small character type*/Letter_capital,/*** Small character + digital type*/Letter_number,/*** Large + small character + digital type*/Letter_capital_number,/*** Large + small character + number + symbol type*/Letter_capital_number_sign}Private Staticstring[] lowercase = {   "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 Staticstring[] Capital = {   "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 Staticstring[] Number = {   "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"}; Private StaticString[] Sign = {   "~", "!", "@", "#", "$", "%", "^", "&", "*", "(", ")", "_", "+", "'", "-", "=",   "{", "}", "|", ":", "\" "," < "," > ","? ",   "[","]","\\",";","‘",",",".","/"}; /*** Static random number*/ Private StaticRandom random =NewRandom (); Public Static voidMain (string[] args) {System.out.println (Password.getrandom (24, PassWord.TYPE.LETTER_CAPITAL_NUMBER_SIGN)); } /*** Get Random Combo code *@paramnum Number of digits *@paramtype * @type * <br> character letter, * <br> uppercase Capital, * <br> Numeric number, * <br> symbol sign  , * <br> large + small character type letter_capital, * <br> small character + digital Letter_number, * <br> large + tiny character + digital Letter_capital_number, * <br> Large + small character + number + symbol type Letter_capital_number_sign*/  Public StaticString Getrandom (intNum,type TYPE) {ArrayList<String> temp =NewArraylist<string>(); StringBuffer Code=NewStringBuffer (); if(Type = =TYPE.  Letter) {Temp.addall (arrays.aslist (lowercase)); }Else if(Type = =TYPE.  Capital) {Temp.addall (arrays.aslist); }Else if(Type = =TYPE.  Number) {Temp.addall (arrays.aslist (number)); }Else if(Type = =TYPE.  Sign) {Temp.addall (arrays.aslist); }Else if(Type = =TYPE.   Letter_capital) {Temp.addall (arrays.aslist (lowercase));  Temp.addall (arrays.aslist (capital)); }Else if(Type = =TYPE.   Letter_number) {Temp.addall (arrays.aslist (lowercase));  Temp.addall (arrays.aslist (number)); }Else if(Type = =TYPE.   Letter_capital_number) {Temp.addall (arrays.aslist (lowercase));   Temp.addall (arrays.aslist (capital));  Temp.addall (arrays.aslist (number)); }Else if(Type = =TYPE.   Letter_capital_number_sign) {Temp.addall (arrays.aslist (lowercase));   Temp.addall (arrays.aslist (capital));   Temp.addall (arrays.aslist (number));  Temp.addall (Arrays.aslist (sign)); }   for(inti = 0; i < num; i++) {code.append (Temp.get (Random.nextint (Temp.size ()))); }  returncode.tostring ();}}

Java randomly generated strings (character randomly generated classes generate random character combinations)

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.