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 ();
}
}