Java Random String getRandomString(int size)

Here you can find the source of getRandomString(int size)

Description

get Random String

License

Apache License

Declaration

public static String getRandomString(int size) 

Method Source Code

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

import java.util.Random;

public class Main {
    private final static char[] c = { '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', 'q', 'w', 'e', 'r', 't',
            'y', 'u', 'i', 'o', 'p', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm',
            'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Z', 'X',
            'C', 'V', 'B', 'N', 'M' };
    private final static int CHART_LENGHT = c.length;

    public static String getRandomString(int size) {
        Random random = new Random();
        StringBuffer sb = new StringBuffer(size);
        for (int i = 0; i < size; i++) {
            sb.append(c[Math.abs(random.nextInt(CHART_LENGHT))]);
        }/*www.  j av a  2s. c  o m*/
        return sb.toString();
    }
}

Related

  1. getRandomString(int length, Random rnd)
  2. getRandomString(int length, String charset)
  3. getRandomString(int min, int max)
  4. getRandomString(int minLength, int maxLength)
  5. getRandomString(int randomPasswordLength)
  6. getRandomString(int size)
  7. getRandomString(int size)
  8. getRandomString(int size)
  9. getRandomString(int size)