生成字符串
import java.util.Random;
/**
* 生成字符串
*/
public class RandomUtil {
/**
* 生成 数字和大小写字母的字符串
*
* @param length
* @return
*/
public String getCharAndNum(int length) {
if (length <= 0){
return "";
}
return this.charAndNum(length);
}
private String charAndNum(int length) {
StringBuffer sb = new StringBuffer();
Random random = new Random();
for (int i = 0; i < length; i++) {
//random.nextInt(2) 0 或1
String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num"; // 输出字母还是数字
if ("char".equalsIgnoreCase(charOrNum)) { //字符串
int choice = random.nextInt(2) % 2 == 0 ? 65 : 97; //取得大写字母还是小写字母
// val += (char) (choice + random.nextInt(26));
sb.append((char) (choice +