Java Random Byte Array randBytes(int length)

Here you can find the source of randBytes(int length)

Description

Returns a byte array of the specified length filled with random values.

License

Open Source License

Parameter

Parameter Description
length length of the returned byte array in bytes

Return

random byte array

Declaration

public static byte[] randBytes(int length) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.Random;

public class Main {
    private static Random rand;

    /**/*from ww  w  .j a  va2s.com*/
     * Returns a byte array of the specified length filled with random values. 
     * @param length length of the returned byte array in bytes
     * @return random byte array
     */
    public static byte[] randBytes(int length) {
        byte[] buf = new byte[length];
        rand.nextBytes(buf);
        return buf;
    }
}

Related

  1. getRandomBytes(int size)
  2. getRandomBytes(int size)
  3. nextBytes(byte[] bytes)
  4. nextBytes(int count)
  5. nextBytes(int length)
  6. randomByte(byte[] b)
  7. randomByteArray(int length)
  8. randomBytes()
  9. randomBytes(byte[] bytes)