Java Random Number Tool class (you can specify a letter or number generation) __java

Source: Internet
Author: User


I write a random number of tools in the company class, more practical.

It can specify how many bits of random digits a letter or number generates.

Package COM.HANYASTAR.UTIL.O;

Import Java.util.Random;  /** * <b> Random Tools </b> * * @author Belen * @version 1.0 * @since 2013-5-16/Public Abstract class Randomutils {public static final char [] letter_number = {' 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 ', ' 0 ', ' 1 ', ' 2 ', ' 3
	
	', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 '};  public static final char [] letter = {' 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 static final Char [] number = {' 0 ', ' 1 ', ' 2 ', ' 3 ', ' 4 ', ' 5 ', ' 6 ', ' 7 ', ' 8 ', ' 9 '};
     /** * generates random numbers in <b>26 English letter </b> by specified size.
     * * @param t * generated length, t can not be less than 1 or greater than 99, otherwise return "0" * @return you want the random number * @created 2013-5-16 02:40:05
  * @author Belen */public static String getrandomofletter (int t) {     Return to get (letter, T);
     /** * generates random numbers in <b>0-9</b> numbers by the specified size.
     * * @param t * generated length, t can not be less than 1 or greater than 99, otherwise return "0" * @return you want the random number * @created 2013-5-16 02:40:05
    * @author Belen */public static String getrandomofnumber (int t) {return get (number, T);
     /** * generates random numbers in <b>25 English and 10 digital </b> at a specified size.
     * * @param t * generated length, t can not be less than 1 or greater than 99, otherwise return "0" * @return you want the random number * @created 2013-5-16 02:40:05 * @author Belen */public static String getrandomofletterandnumber (int t) {return get (Letter_numbe
    R, T); /** generates data by the specified array.
    	* * private static String get (char[] c, int t) {if (T < 1 | | | t >) {return "0";
		final int maxnum = 36; int i; generated random number int count = 0;
		The generated length stringbuffer sb = new StringBuffer ("");
		Random r = new Random (); while (Count < T) {//Generate random numbers, take absolute values to prevent negative numbers from being generated, I =Math.Abs (R.nextint (maxnum));
				The maximum number of generated is 36-1 if (i >= 0 && i < c.length) {sb.append (c[i]);
			count++;
	} return 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.