Java Utililty Methods Random Byte Array

List of utility methods to do Random Byte Array

Description

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

Method

byte[]generateRandomArray()
Generate random array.
int size = 20000;
byte[] byteArray = new byte[size];
for (int i = 0; i < size; i++) {
    byteArray[i] = (byte) (Math.random() * 127f);
return byteArray;
byte[]generateRandomBlob()
generate Random Blob
return generateRandomBlob(65536);
byte[]generateRandomByteArray(int length)
generate Random Byte Array
return generateRandomByteArray(length, false, (byte) 0);
byte[]generateRandomByteArray(int length)
generate Random Byte Array
byte[] line = new byte[length];
for (int i = 0; i < length; i++) {
    byte rand = (byte) ((int) (Math.random() * 255) - 128);
    line[i] = rand;
return line;
byte[]generateRandomByteArray(int length, boolean avoid, byte avoidByte)
Create an array of random bytes
byte[] line = new byte[length];
for (int i = 0; i < length; i++) {
    byte rand;
    do {
        rand = (byte) ((int) (Math.random() * 255) - 128);
    } while (avoid && rand == avoidByte);
    line[i] = rand;
return line;
byte[]generateRandomByteArray(int size)
generate Random Byte Array
return getRandomByteArray(size);
byte[]generateRandomByteArray(int size, Random rnd)
Return a bytearray of random data with specified size.
if (rnd == null) {
    rnd = new Random();
byte[] data = new byte[size];
rnd.nextBytes(data);
return data;
byte[]generateRandomBytes()
generate Random Bytes
int length = rng.nextInt(200);
return generateRandomBytes(length);
byte[]generateRandomBytes(final int pSize)
Generating random bytes.
final byte[] returnVal = new byte[pSize];
random.nextBytes(returnVal);
return returnVal;
byte[]generateRandomBytes(int n)
generate Random Bytes
byte[] bytes = new byte[n];
synchronized (tempFileRandom) {
    tempFileRandom.nextBytes(bytes);
return bytes;