當前位置:名人名言大全網 - 端午節短信 - JAVA程序,隨機生成壹個6位驗證碼(由0

JAVA程序,隨機生成壹個6位驗證碼(由0

導入Java . util . random;

公共類TestRandom {

公共字符串getRandStr(int charCount) {

String charValue =

for(int I = 0;我& ltcharCounti++){

char c =(char)(random nt(0,26)+' a ');

char value+= string . value of(c);

}

返回charValue

}

公共字符串getRandNum(int charCount) {

String charValue =

for(int I = 0;我& ltcharCounti++){

char c =(char)(random nt(0,10)+' 0 ');

char value+= string . value of(c);

}

返回charValue

}

public int randomInt(int from,int to){

Random r = new Random();

return from+r . nextint(to-from);

}

}