Here you can find the source of randomBytes(int size)
public static byte[] randomBytes(int size)
//package com.java2s; //License from project: Apache License public class Main { public static byte[] randomBytes(int size) { byte[] bytes = new byte[size]; for (int index = 0; index < size; index++) { bytes[index] = (byte) randomNumber(0, 255); }//from w w w . j a v a 2 s . c o m return bytes; } private static int randomNumber(int minimum, int maximum) { return (int) (Math.random() * maximum + minimum); } }