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

byte[]randomByteArray(int length)
Create an array of random bytes
return randomByteArray(length, false, (byte) 0);
byte[]randomByteArray(int size, byte from, byte to)
random Byte Array
byte width = (byte) (to - from);
byte[] result = new byte[size];
for (int i = 0; i < size; i++)
    result[i] = (byte) (((Math.random() * width) % width) + from);
return result;
intrandomByteAsInt()
random Byte As Int
return (int) (Math.random() * 0xFF);
byte[]randomBytes(int size)
random Bytes
byte[] bytes = new byte[size];
for (int index = 0; index < size; index++) {
    bytes[index] = (byte) randomNumber(0, 255);
return bytes;
byte[]randomBytes(int size)
random Bytes
byte[] bb = bytes;
byte[] ab = new byte[size];
for (int i = 0; i < size; i++) {
    ab[i] = randomByte(bb);
return ab;
int[]randomCommon(int min, int max, int n)
random Common
if (max == min + n) {
    return null;
if (n > (max - min + 1) || max < min) {
    return null;
int[] result = new int[n];
int count = 0;
...
StringrandomCommonStr(int min, int max, int n)
random Common Str
int[] arr = randomCommon(min, max, n);
String tmp = "";
for (int i = 0; i < arr.length; i++) {
    tmp += arr[i] + "";
return tmp;
double[][]randomDoubleMatrix(int rows, int columns)
Creates a random matrix.
double[][] matrix = new double[rows][columns];
for (int i = 0; i < matrix.length; i++) {
    for (int j = 0; j < matrix[i].length; j++) {
        matrix[i][j] = Math.random();
return matrix;
floatrandomFloatInInterval(float lower, float upper)
random Float In Interval
return (float) (Math.random() * (Math.abs(upper - lower)) + lower);
StringrandomHex(int length)
random Hex
StringBuilder buf = new StringBuilder();
for (int i = 0; i < length; i++) {
    buf.append(Long.toHexString((long) (Math.random() * 16)));
return buf.toString();