Android 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

voidfillRandomBytes(byte[] bytes)
fill Random Bytes
Random ran = new Random();
for (int i = 0; i < bytes.length; ++i) {
    if (i > 0 && i % 120 == 0) {
        bytes[i] = '\n';
    } else {
        bytes[i] = (byte) (ran.nextInt(10) + 48);
bytegetRandomByte()
get Random Byte
byte randomNum = 0;
Random random = new Random();
int num = Math.abs(random.nextInt() % 256);
randomNum = (byte) num;
Log.d("", "--> getRandomNum num : " + num + "  ,  randomNum : "
        + (randomNum & 0xFF));
return randomNum;
byte[]getRandomByteArrays(int arrSize)
get Random Byte Arrays
byte[] byteArr = new byte[arrSize];
for (int i = 0; i < arrSize; i++) {
    byteArr[i] = getRandomByte();
return byteArr;
intrandomInt(int min, int max)
random Int
Random random = new Random(System.currentTimeMillis());
return min + random.nextInt(max - min);
StringrandomStr(int length)
random Str
String hash = "";
String charStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
char chars[] = charStr.toCharArray();
int max = chars.length;
Random random = new Random();
for (int i = 0; i < length; i++) {
    hash += chars[Math.abs(random.nextInt()) % max];
return hash;
StringrandomStr(int length)
random Str
String hash = "";
String charStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz";
char chars[] = charStr.toCharArray();
int max = chars.length;
Random random = new Random();
for (int i = 0; i < length; i++) {
    hash += chars[Math.abs(random.nextInt()) % max];
return hash;
byte[]generateSalt()
generate Salt
SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
byte[] salt = new byte[16];
random.nextBytes(salt);
return salt;
byte[]generateSalt()
generate Salt
byte[] salt = new byte[24];
RANDOM.nextBytes(salt);
return salt;
byte[]getRandomBytes(final int size)
get Random Bytes
final SecureRandom random = new SecureRandom();
final byte[] bytes = new byte[size];
random.nextBytes(bytes);
return bytes;