public static BufferedImage generateRandomImage(int numOfPixels) throws OpenStegoException {
  final double ASPECT_RATIO=4.0 / 3.0;
  int width=0;
  int height=0;
  byte[] rgbValue=new byte[3];
  BufferedImage image=null;
  SecureRandom random=null;
  try {
    random=SecureRandom.getInstance("SHA1PRNG");
    width=(int)Math.ceil(Math.sqrt(numOfPixels * ASPECT_RATIO));
    height=(int)Math.ceil(numOfPixels / (double)width);
    image=new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
    for (int x=0; x < width; x++) {
      for (int y=0; y < height; y++) {
        random.nextBytes(rgbValue);
        image.setRGB(x,y,CommonUtil.byteToInt(rgbValue[0]) + (CommonUtil.byteToInt(rgbValue[1]) << 8) + (CommonUtil.byteToInt(rgbValue[2]) << 16));
      }
    }
    return image;
  }
 catch (  NoSuchAlgorithmException nsaEx) {
    throw new OpenStegoException(nsaEx);
  }
}

public static BufferedImage generateRandomImage ( int numOfPixels ) throws OpenStegoException { final double ASPECT_RATIO = 4.0 / 3.0 ; int width = 0 ; int height = 0 ; byte [ ] rgbValue = new byte [ 3 ] ; BufferedImage image = null ; SecureRandom random = null ; try { random = SecureRandom . getInstance ( "SHA1PRNG" ) ; width = ( int ) Math . ceil ( Math . sqrt ( numOfPixels * ASPECT_RATIO ) ) ; height = ( int ) Math . ceil ( numOfPixels / ( double ) width ) ; image = new BufferedImage ( width , height , BufferedImage . TYPE_INT_RGB ) ; for ( int x = 0 ; x < width ; x ++ ) { for ( int y = 0 ; y < height ; y ++ ) { random . nextBytes ( rgbValue ) ; image . setRGB ( x , y , CommonUtil . byteToInt ( rgbValue [ 0 ] ) + ( CommonUtil . byteToInt ( rgbValue [ 1 ] ) << 8 ) + ( CommonUtil . byteToInt ( rgbValue [ 2 ] ) << 16 ) ) ; } } return image ; } catch ( NoSuchAlgorithmException nsaEx ) { throw new OpenStegoException ( nsaEx ) ; } }
method to generate a random image filled with noise .
