Java Random - How to create random words in Java?

Code Snippets Java Random Java 

public class RandomWord {
public static void main(String[] args) {
for (int i = 0; i < 10; i++) {
String randomWord = createRandomWord(6);
System.out.println(randomWord);
}
}

public static String createRandomWord(int len) {
String name = "";
for (int i = 0; i < len; i++) {
int v = 1 + (int) (Math.random() * 26);
char c = (char) (v + (i == 0 ? 'A' : 'a') - 1);
name += c;
}
return name;
}
}

Output

Yqadir
Avntwf
Ijarfj
Fcksph
Tvsnhm
Itnlch
Ecnmsd
Ocbqyh
Rdrhos
Uripkd




See Also