use a string that contains your alphabet and generate a random number that access the index of the string.
import java.util.Random;
public class RandomAlphabet {
public String getRandomString(int length) {
final StringBuilder randomString = new StringBuilder();
final String alphabetPool = "abcdefghijklmnoABCDEFGHIJKLMNO";
final int endRange = alphabetPool.length()-1;
final Random rand = new Random();
for (int i = 0; i < length; i++) {
randomString.append(alphabetPool.charAt(rand.nextInt(endRange)));
}
return randomString.toString();
}
}
something along the line of this?
or do you mean real mathematical alphabets ? within the unicode range?
import java.io.UnsupportedEncodingException;
import java.util.Random;
public class RandomAlphabet {
public static void main(String[] args) throws UnsupportedEncodingException {
System.out.println(RandomAlphabet.getRandomString(10));
System.out.println(RandomAlphabet.getRandomAlphabet(10));
}
private static String getRandomString(int length) {
final StringBuilder randomString = new StringBuilder();
final String alphabetPool = "abcdefghijklmnoABCDEFGHIJKLMNO";
final int endRange = alphabetPool.length()-1;
final Random rand = new Random();
for (int i = 0; i < length; i++) {
randomString.append(alphabetPool.charAt(rand.nextInt(endRange)));
}
return randomString.toString();
}
private static String getRandomAlphabet(int length) throws UnsupportedEncodingException {
final StringBuilder randomAlphabet = new StringBuilder();
final Random rand = new Random();
for (int i = 0; i < length; i++) {
int randomInt = rand.nextInt(65535);
String hexString = "\\u"+Integer.toHexString(randomInt);
randomAlphabet.append(hexString);
}
return new String(randomAlphabet.toString().getBytes("UTF8"), "UTF-8");
}
}
since the highest unicode value is FFFF which is 65535 you should be able to use random integer representations between 0 - 65535 to real get a random alphabet.
these are just experimental thoughts though.