Get Random bytes in Java
Description
The following code shows how to get Random bytes.
Example
//from w w w. j a v a2 s . c o m
import java.util.Arrays;
import java.util.Random;
public class Main {
public static void main(String[] argv) throws Exception {
Random rand = new Random();
byte[] bytes = new byte[5];
rand.nextBytes(bytes);
System.out.println(Arrays.toString(bytes));
}
}
The code above generates the following result.