Java Random String getRandomString(int min, int max)

Here you can find the source of getRandomString(int min, int max)

Description

get Random String

License

Open Source License

Declaration

public static String getRandomString(int min, int max) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Random;

public class Main {
    public static String getRandomString(int min, int max) {
        String newstring = new String();
        Random rand = new Random();
        int i;/* w  ww. j  a  v  a  2s .c om*/
        final char[] chars = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i',
                'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u',
                'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
                'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S',
                'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '!', '@', '#', '$', '%',
                '^', '&', '*', '(', ')', '_', '-', '=', '+', '{', '}', '[',
                ']', '|', ':', ';', ',', '.', '?', '/', '~', ' ' }; // 79
        // characters
        int strlen = (int) Math.floor(rand.nextDouble() * (max - min + 1));
        strlen += min;
        for (i = 0; i < strlen; i++) {
            char c = chars[(int) Math.floor(rand.nextDouble() * 79)];
            newstring = newstring.concat(String.valueOf(c));
        }
        return newstring;
    }
}

Related

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