Java Utililty Methods Random Int

List of utility methods to do Random Int

Description

The list of methods to do Random Int are organized into topic(s).

Method

voidrandomQuickSort(int[] array)
random quick sort
randomQuickSort(array, 0, array.length);
intrandomRange(int min, int max)
random Range
return min + (int) (Math.random() * ((max - min) + 1));
intrandomSize(int maxValue)
random Size
return randomIndex(maxValue) + 1;
StringrandomSMSCode(int length)
random SMS Code
boolean numberFlag = true;
String retStr = "";
String strTable = numberFlag ? "1234567890" : "1234567890abcdefghijkmnpqrstuvwxyz";
int len = strTable.length();
boolean bDone = true;
do {
    retStr = "";
    int count = 0;
...
StringrandomStr(int length)
random Str
return random(length, ALPHABET);
StringrandomStr(int length, String charSet)
Generates random alphanumeric String of the specified length using characters specified in charSet.
char[] result = new char[length];
fillWithRandomChars(result, charSet);
return new String(result);
StringrandomString(int count)
random String
StringBuilder b = new StringBuilder();
int len = chars.length();
for (int i = 0; i < count; i++) {
    b.append(chars.charAt((int) (Math.random() * len)));
return b.toString();
StringrandomString(int length)
random String
char[] guts = new char[length];
for (int i = 0; i < length; i++) {
    guts[i] = Character.toChars(65 + (int) (Math.random() * 26))[0];
return String.valueOf(guts);
StringrandomString(int length)
Generate a random string of characters - including numbers
StringBuffer b = new StringBuffer(length);
for (int i = 0; i < length; i++) {
    b.append(randomAlpha());
return b.toString();
StringrandomString(int length)
random String
String chars = "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIFKLMNOPRSTUVWXYZ" + "0123456789";
StringBuffer buf = new StringBuffer(length);
for (int i = 0; i < length; ++i) {
    int pos = (int) Math.round(Math.random() * (chars.length() - 1));
    buf.append(chars.charAt(pos));
return buf.toString();