Java Random String randomString(Random r, int minCount, int maxCount)

Here you can find the source of randomString(Random r, int minCount, int maxCount)

Description

random String

License

Apache License

Declaration

public static String randomString(Random r, int minCount, int maxCount) 

Method Source Code

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

import java.util.*;

public class Main {
    public static String randomString(Random r, int minCount, int maxCount) {
        minCount = Math.max(Math.min(minCount, maxCount), 1);
        maxCount = Math.max(minCount, maxCount);
        final int stringCount = minCount + r.nextInt(maxCount - minCount);
        char[] s = new char[stringCount];

        for (int i = 0; i < stringCount; ++i) {
            s[i] = (char) (32 + r.nextInt(127 - 32));
        }//from   w w  w .j  a  v  a2 s. c  o  m

        return new String(s);
    }
}

Related

  1. randomString(int length)
  2. randomString(int length)
  3. randomstring(int lo, int hi)
  4. randomString(int stringLength)
  5. randomString(Integer len)
  6. randomSubset(String[] list, int count)
  7. randomSuffix(final String name)
  8. randomUnicodeString(Random r)
  9. Shuffle(ArrayList list, Random randomNumberGenerator)