-3

How to generate a random alphanumeric string that's limited to 10 character in netbeans, im trying to save an attachment file as a random alphanumeric filename.

MaxZoom
  • 7,619
  • 5
  • 28
  • 44
  • Is _netbeans_ an important part of the question or is is just about _Java_? – dotvav Aug 04 '15 at 15:28
  • 2
    you have to show some effort of your own. read about random in java, think about how using it, converting numbers to strings and chars, using string manipulation, ... – hoijui Aug 04 '15 at 15:28
  • If you don't write more then one file per minute, you can use current time as a unique string for your file name `YY MM DD hh mm` – MaxZoom Aug 04 '15 at 15:31
  • You should have tried to look for it at least once before asking it on SO. I wonder how did you miss the related questions prompted while creating this question as well. – Vamshi Krishna Alladi Aug 04 '15 at 15:40

1 Answers1

0

Use random and string builder for max efficiency.

Random rand = new Random();
StringBuilder stringBuilder = new StringBuilder("")
char[] chars = {'a','b', ...}
for (int i = 0; i < 10; ++i) {
    char selectedChar = chars[rand.nextInt(chars.length)];
    stringBuilder.append(selectedChar);
}
String string = stringBuilder.toString();
Anon10W1z
  • 167
  • 10