如何生成随机字符?
像这样的随机数::
public static int random() {
Random generator = new Random();
int x = generator.nextInt(10000);
return x;
}
我需要画出类似的东西:zCs3v3b1b6 just random chars
public static char random() {
Random generator = new Random();
char x = (char)(generator.nextInt(96) + 32);
return x;
}
这将生成一个随机字符。
public static void main(String[] args) {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < 8; i++)
builder.append(random());
System.out.println(builder.toString());
}
这将生成一个包含 8 个随机字符的字符串
见以下链接:http ://www.asciitable.com/
public static char randomSeriesForThreeCharacter() {
Random r = new Random();
char random_3_Char = (char) (48 + r.nextInt(47));
return random_3_Char;
}