Java Password Generate generateString(String charSet, int len)

Here you can find the source of generateString(String charSet, int len)

Description

generate String

License

Open Source License

Declaration

public static String generateString(String charSet, int len) 

Method Source Code

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

import java.util.Random;

public class Main {
    public static String generateString(String charSet, int len) {
        return generateString(charSet, len, len);
    }/*ww  w .j  a  va 2 s. c  o m*/

    public static String generateString(String charSet, int minLen, int maxLen) {
        Random rng = new Random();
        int len = minLen;

        if ((maxLen - minLen) > 0) {
            len += rng.nextInt(maxLen - minLen);
        }

        char[] text = new char[len];
        for (int i = 0; i < len; i++) {
            text[i] = charSet.charAt(rng.nextInt(charSet.length()));
        }
        return new String(text);
    }
}

Related

  1. generateString(int length)
  2. generateString(int length)
  3. GenerateString(int Length)
  4. generateString(int maxlength)
  5. generateString(String alphabet, int length)
  6. generateStrings(int count, int length)
  7. generateStringsEntries(int cnt)
  8. getDummyPassword()