Here you can find the source of randomByteArray(int size, byte from, byte to)
public static byte[] randomByteArray(int size, byte from, byte to)
//package com.java2s; /**//www .j a v a 2 s . c o m * This class is part of JCodec ( www.jcodec.org ) This software is distributed * under FreeBSD License * * @author Jay Codec * */ public class Main { public static byte[] randomByteArray(int size, byte from, byte to) { 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; } }