Java Random Byte Array randomBytes(int size)

Here you can find the source of randomBytes(int size)

Description

Returns a random byte array.

License

Open Source License

Parameter

Parameter Description
size - number of bytes to return

Return

random byte array

Declaration

public static byte[] randomBytes(int size) 

Method Source Code

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

import java.util.Random;

public class Main {
    /**/*www  .j  a  v a2s. co  m*/
     * Returns a random byte array. Note: Does not use a secure random number
     * generator.
     * 
     * @param size
     *            - number of bytes to return
     * @return random byte array
     * 
     * @see {@link SecureRandom}
     */
    public static byte[] randomBytes(int size) {
        byte[] saltBytes = new byte[size];
        new Random().nextBytes(saltBytes);
        return saltBytes;
    }
}

Related

  1. randomBytes(byte[] bytes)
  2. randomBytes(final int numBytes)
  3. randomBytes(int length)
  4. randomBytes(int length)
  5. randomBytes(int minimumCharacters, int maximumCharacters)
  6. randomBytes(long seed, int blockCount, int blockSize)
  7. randomBytes(Random r, int length)
  8. randomBytes(Random rand, int size)
  9. randomBytesSlowNextInt(Random r, byte[] buf, int from, int len)