学习代码记录
/**
* 随机生成指定长度的字符串
*
* @param
* @param lengthOfString
* @return 纯字母字符串
*/
public static String getRndStrByLen(int lengthOfString) {
int i, count = 0;
final String chars = "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";
String[] charArr = chars.split(",");
StringBuffer randomStr = new StringBuffer("");
Random rnd = new Random();
int strLen = charArr.length;
while (count < lengthOfString) {
i = rnd.nextInt(strLen);// strLen如果等于26,i值就在0-25之间
randomStr.append(charArr[i]);
count++;
}
return randomStr.toString().toLowerCase();
}
@Test
private void InitDriver() {
String a = Randomo.getRndStrByLen(2); //没有清楚需要用get方式获取数据,还的继续学习
System.out.println(a);
}