Reputation: 119
How to generate random chars ?
Random numbers like this: :
public static int random() {
Random generator = new Random();
int x = generator.nextInt(10000);
return x;
}
I need to draw something like: zCs3v3b1b6 just random chars
Upvotes: 0
Views: 854
Reputation: 38409
See below link : 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;
}
Upvotes: 0
Reputation: 1534
public static char random() {
Random generator = new Random();
char x = (char)(generator.nextInt(96) + 32);
return x;
}
This would generate a random char.
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());
}
This would generate a string with 8 random characters
Upvotes: 2