1. System.currentTimeMillis();
2. Math.random(); 返回一个随机双精度值d, 如:0.0 <= d <= 1.0
一般地,a + Math.random() * b ; 返回 a 到 a+b 之间的随机数,不包括 a+b .
3. 生成任意两个字符 ch1 和 ch2 (ch1 < ch2)之间的随机字符:
(char)(ch1 + Math.random() * (ch2 - ch1 + 1));
4. 五个求特定类型随机字符的重载方法:
public class RandomCharacter {
public static char getRandomCharacter(char ch1, char ch2){
return (char)(ch1 + Math.random() * (ch2 - ch1 + 1));
}
public static char getRandomLowerCaseLetter(){
return getRandomCharacter('a', 'z');
}
public static char getRandomUpperCaseLetter(){
return getRandomCharacter('A', 'Z');
}
public static char getRandomDigitCaseLetter(){
return getRandomCharacter('0', '9');
}
public static char getRandomCharacter(){
return getRandomCharacter('\u0000', '\uFFFF');
}
}