Java randomly generated string tool class

Source: Internet
Author: User

 PackageAA;Importjava.util.ArrayList;Importjava.util.Arrays;ImportJava.util.Random;/*** Character randomly generated class*/ Public classRandomdemo {/*** Randomly generated type enumeration*/     Public Static enumTYPE {/**Small character Type*/Letter ,/**Uppercase Character type*/Capital ,/**Digital Type*/Number ,/**Large + small character type*/Letter_capital,/**Small character + digital type*/Letter_number,/**uppercase characters + numbers*/Capital_number,/**Large + small character + digital type*/Letter_capital_number,}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" }; /*** Static random number*/    Private StaticRandom random =NewRandom ();/*** Get Random Combo code *@paramnum Number of digits *@paramtype * @type * <br> lowercase letter, * <br> uppercase Capital, * <br> Digital number, * & lt;br> Large + small character type letter_capital, * <br> characters + digital Letter_number, * <br> big characters + digital Capital_number, * < ;br> Large + small character + digital type Letter_capital_number,*/     Public StaticString Getrandom (intnum, type type) {ArrayList<String> temp =NewArraylist<string>(); StringBuffer Code=NewStringBuffer (); Switch(type) { CaseLETTER:temp.addAll (arrays.aslist (lowercase));  Break;  CaseCAPITAL:temp.addAll (arrays.aslist (capital));  Break;  CaseNUMBER:temp.addAll (arrays.aslist (number));  Break;  CaseLETTER_CAPITAL:temp.addAll (arrays.aslist (lowercase));            Temp.addall (arrays.aslist (capital));  Break;  CaseLETTER_NUMBER:temp.addAll (arrays.aslist (lowercase));            Temp.addall (arrays.aslist (number));  Break;  CaseCAPITAL_NUMBER:temp.addAll (arrays.aslist (capital));            Temp.addall (arrays.aslist (number));  Break;  CaseLETTER_CAPITAL_NUMBER:temp.addAll (arrays.aslist (lowercase));            Temp.addall (arrays.aslist (capital));            Temp.addall (arrays.aslist (number));  Break; }         for(inti = 0; i < num; i++) {code.append (Temp.get (Random.nextint (Temp.size ()))); }        returncode.tostring (); }
Test
  void Main (string[] args) {        System.out.println (Randomdemo.getrandom (Ten, RandomDemo.TYPE.LETTER_CAPITAL) ); }
}

Java randomly generated string tool class

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.