Skip to content

Instantly share code, notes, and snippets.

@FrankCharlz
Created May 21, 2016 15:46
Show Gist options
  • Select an option

  • Save FrankCharlz/5932215abdf79262fcaa736e21910113 to your computer and use it in GitHub Desktop.

Select an option

Save FrankCharlz/5932215abdf79262fcaa736e21910113 to your computer and use it in GitHub Desktop.
public class M {
private String generateRandomString(int length) {
Random rn = new Random();
char small = 'a';
char capital = 'A';
StringBuilder sb = new StringBuilder(length);
for (int i=0; i<length; i++){
if(rn.nextBoolean())
sb.append((char)(small + rn.nextInt(26)));
else
sb.append((char)(capital + rn.nextInt(26)));
}
return sb.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment