you can create random words like this:
use method Math.random() for random int values.
cast these int values into a char value.
example: char c = (char) 65;
for that, you have to read about ASCII values. (65 casts to 'A')
i wrote a full example, which you can use.
public class Test {
private static String createWord(int wordlength) {
String word = "";
for (int i = 0; i < wordlength; i++) {
int ran = (int) (Math.random() * 2);
if (ran == 0)
word += (char) (int) (Math.random() * 26 + 'A');
else
word += (char) (int) (Math.random() * 26 + 'a');
}
return word;
}
public static void main(String[] args) {
System.out.println(createWord(8));
}
}
this answer is just about creating random words.
if you want to exchange random char
s in a word/String, you can take a look at String's replace(oldChar, newChar) method in combination with creating random chars with Math.random().
EDIT: Do you want to change a char into a wildcard (word -> wo.d), or into some random letter (word -> wKrd)?
for the second one you can use following method:
private static String replaceCharInWord(String word) {
int random = (int) (Math.random() * word.length());
System.out.println(random);
int ran = (int) (Math.random() * 2);
char newChar = ' ';
if (ran == 0)
newChar = (char) (int) (Math.random() * 26 + 'A');
else
newChar = (char) (int) (Math.random() * 26 + 'a');
return word.substring(0, random) + newChar + word.substring(random + 1);
}