Android Random String Create getRandomStr(int length)

Here you can find the source of getRandomStr(int length)

Description

get Random Str

License

Apache License

Declaration

public static String getRandomStr(int length) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Random;

public class Main {
    private static final char[] SOURCE = "123456789abcdefghijklmnpqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ"
            .toCharArray();//ww  w .  ja  v a  2  s  .c  om

    public static String getRandomStr(int length) {
        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);
            buf[i] = SOURCE[index];
        }
        return new String(buf);
    }
}

Related

  1. getRandomString(int len)
  2. getRandomString(int length)
  3. randomString(int size)
  4. randomIVString()
  5. getRandomString()