List of utility methods to do Random Byte Array
void | fillRandomBytes(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); |
byte | getRandomByte() 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; |
int | randomInt(int min, int max) random Int Random random = new Random(System.currentTimeMillis()); return min + random.nextInt(max - min); |
String | randomStr(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; |
String | randomStr(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; |