Java Random String getRandomString(int size)

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

Description

get Random String

License

LGPL

Parameter

Parameter Description
size a parameter

Declaration

public static String getRandomString(int size) 

Method Source Code

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

public class Main {
    /**/*from   ww w. j a va  2s  . c  o m*/
     * 
     * @param size
     * @return
     */
    public static String getRandomString(int size) {
        char[] vals = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
                'Q', 'W', 'E', 'R', 'T', 'Z', 'U', 'I', 'O', 'P', 'A', 'S',
                'D', 'F', 'G', 'H', 'J', 'K', 'L', 'Y', 'X', 'C', 'V', 'B',
                'N', 'M' };
        String randomString = "";
        java.util.Random rand = new java.util.Random();
        for (int i = 0; i < size; i++)
            randomString += vals[rand.nextInt(size)];

        return randomString;
    }
}

Related

  1. getRandomString(int minLength, int maxLength)
  2. getRandomString(int randomPasswordLength)
  3. getRandomString(int size)
  4. getRandomString(int size)
  5. getRandomString(int size)
  6. getRandomString(int size)
  7. getRandomString(int size)
  8. getRandomString(int strLength)
  9. getRandomString(Random random, int minLen, int maxLen)