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

intrandom_range(int x1, int x2)
Returns a random real number between x1 (inclusive) and x2 (exclusive).
return (int) (Math.floor(x1 + (Math.random() * (x2 - x1))));
intrandomActorId(int max)
random Actor Id
int min = 0;
return randomNumber(min, max);
StringrandomAlphaNum(int length)
Generates random alphanumeric String of the specified length.
char[] result = new char[length];
fillWithRandomAlphaNum(result);
return new String(result);
StringrandomAlphanumeric(int count)
random Alphanumeric
char[] chars = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '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' };
StringBuilder res = new StringBuilder();
for (int i = 0; i < count; i++) {
    res.append(chars[(int) (chars.length * Math.random())]);
return res.toString();
StringrandomAlphanumericString(int length)
random Alphanumeric String
String set = "abcdefghijklmnopqrstuwxyz0123456789";
StringBuilder builder = new StringBuilder();
for (int i = 0; i < length; i++) {
    builder.append(set.charAt(randomNumber(0, set.length())));
return builder.toString();
StringrandomAlphaString(int length)
random Alpha String
StringBuilder builder = new StringBuilder(length);
for (int i = 0; i < length; i++) {
    char c = (char) (65 + 25 * Math.random());
    builder.append(c);
return builder.toString();
double[]randomArray(int len)
random Array
double[] data = new double[len];
for (int i = 0; i < len; i++) {
    data[i] = 0;
return data;
int[]randomArray(int min, int max, int n)
Generate n random and different numbers within specified non-negative integer range
if (n > (max - min + 1) || max < min || min < 0 || max < 0) {
    return null;
int[] result = new int[n];
for (int i = 0; i < n; i++) {
    result[i] = -1;
int count = 0;
...
StringrandomBases(int n)
Generate a string of random bases of length n.
StringBuilder sb = new StringBuilder();
for (int i = 0; i < n; i++) {
    int pick = (int) Math.floor(Math.random());
    switch (pick % 4) {
    case 0:
        sb.append("T");
        break;
    case 1:
...
voidrandomBlock(byte[] block, int off, int len)
random Block
for (int i = off; i < off + len; ++i)
    block[i] = (byte) (Math.random() * 256.0);