Here you can find the source of generateStringFromCharacters(final Random random, final char[] validChars, final int min, final int max)
Parameter | Description |
---|---|
validChars | to chose from |
min | length of the string |
max | length of the string |
public static String generateStringFromCharacters(final Random random, final char[] validChars, final int min, final int max)
//package com.java2s; //License from project: Open Source License import java.util.Random; import java.util.concurrent.ThreadLocalRandom; public class Main { /**//from w w w. j av a2 s .co m * Generate a random string from an array of characters * * @param validChars to chose from * @param min length of the string * @param max length of the string * @return */ public static String generateStringFromCharacters(final Random random, final char[] validChars, final int min, final int max) { final int size = ThreadLocalRandom.current().nextInt(min, max + 1); final char[] localPart = new char[size]; for (int i = 0; i < size; i++) { localPart[i] = validChars[random.nextInt(validChars.length - 1)]; } return new String(localPart); } }