Here you can find the source of generateRandomBytes(int num)
Parameter | Description |
---|---|
num | is the number for random bytes to generate. |
public static byte[] generateRandomBytes(int num)
//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; } }