Java Random Byte Array generateRandomBytes(int num)

Here you can find the source of generateRandomBytes(int num)

Description

This function generates a specified number of random bytes.

License

Open Source License

Parameter

Parameter Description
num is the number for random bytes to generate.

Return

An array of bytes is returned containing the random numbers.

Declaration

public static byte[] generateRandomBytes(int num) 

Method Source Code


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

import java.util.Random;

public class Main {
    private static final Random random = new Random(System.nanoTime());

    /**/*w ww . j ava2s .co  m*/
     * This function generates a specified number of random bytes. These bytes
     * can be used for security keys.
     * 
     * @param num
     *            is the number for random bytes to generate.
     * @return An array of bytes is returned containing the random numbers.
     */
    public static byte[] generateRandomBytes(int num) {
        byte[] randomBytes = new byte[num];
        random.nextBytes(randomBytes);
        return randomBytes;
    }
}

Related

  1. generateRandomByteArray(int size)
  2. generateRandomByteArray(int size, Random rnd)
  3. generateRandomBytes()
  4. generateRandomBytes(final int pSize)
  5. generateRandomBytes(int n)
  6. generateRandomBytes(int num_to_generate)
  7. generateRandomBytes(int num_to_generate)
  8. generateRandomBytes(int size)
  9. getRandomByteArray(int len)