I am using String Builder from another answer, but I cannot use anything other than alpha / numeric, without spaces, punctuation, etc. Can you explain how to limit the character set in this code? Also, how can I guarantee that it ALWAYS lasts 30 characters?
Random generator = new Random(); StringBuilder stringBuilder = new StringBuilder(); int Length = 30; char tempChar ; for (int i = 0; i < Length; i++){ tempChar = (char) (generator.nextInt(96) + 32); stringBuilder.append(tempChar);
I went through most of the other answers and cannot find a solution to this. Thank you Do not yell at me if this is a duplicate. Most answers do not explain how much of the code determines how long the generated number is or where you can configure the character set.
I also tried stringBuilder.Replace ('', '1'), which might work, but eclipse says there is no method for Replace for StringBuilder.
java string random alphanumeric
PrivusGuru
source share