Android Utililty Methods Random String Create

List of utility methods to do Random String Create

Description

The list of methods to do Random String Create are organized into topic(s).

Method

StringgetRandomString(int len)
get Random String
String returnStr = "";
char[] ch = new char[len];
Random rd = new Random();
for (int i = 0; i < len; i++) {
    ch[i] = (char) (rd.nextInt(9) + 97);
returnStr = new String(ch);
return returnStr;
...
StringgetRandomStr(int length)
get Random Str
if (length < 1) {
    return null;
Random random = new Random();
char[] buf = new char[length];
int index = 0;
for (int i = 0; i < length; i++) {
    index = random.nextInt(SOURCE.length);
...
StringgetRandomString(int length)
get Random String
Random random = new Random(System.currentTimeMillis());
byte[] randomBytes = new byte[length];
for (int i = 0; i < length; i++) {
    randomBytes[i] = CHARS[random.nextInt(CHARS.length)];
return new String(randomBytes);
StringrandomString(int size)
random String
StringBuilder sb = new StringBuilder();
for (int i = 0; i < size; i++) {
    sb.append((char) (((int) 'A') + Math.random() * 25));
return sb.toString();
StringrandomIVString()
random IV String
return new BigInteger(130, random).toString(16);
StringgetRandomString()
get Random String
final SecureRandom random = new SecureRandom();
return String.valueOf(random.nextLong());
StringgetRandomPwd()
get Random Pwd
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 6; i++) {
    sb.append(getRandomIntNum(9));
return sb.toString();
StringgenRandomString(int pLength)
gen Random String
Random r = new Random();
String letter = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
StringBuffer sb = new StringBuffer();
for (int i = 0; i < pLength; i++) {
    sb.append(letter.charAt(r.nextInt(1000000) % (letter.length())));
return sb.toString();
StringgenerateRandom()
generate Random
Random number = new Random();
StringBuilder message = new StringBuilder();
for (int i = 0; i < 1405; i++) {
    message.append('a' + number.nextInt(52));
return message.toString();
StringrandomAlphaNumeric(int length)
random Alpha Numeric
StringBuffer buffer = new StringBuffer();
String characters = "abcdefghijklmnopqrstuvwxyz0123456789";
int charactersLength = characters.length();
for (int i = 0; i < length; i++) {
    double index = Math.random() * charactersLength;
    buffer.append(characters.charAt((int) index));
return buffer.toString();
...