Java SecureRandom() Constructor

Syntax

SecureRandom() constructor from SecureRandom has the following syntax.

public SecureRandom()

Example

In the following code shows how to use SecureRandom.SecureRandom() constructor.


//w  w w.  j  av a2  s .c o m
import java.security.SecureRandom;
import java.util.Arrays;

public class Main {
  public static void main(String[] argv) throws Exception {
    SecureRandom sr = new SecureRandom();

    byte[] bytes = new byte[8];
    sr.nextBytes(bytes);
    System.out.println(Arrays.toString(bytes));
  }
}




















Home »
  Java Tutorial »
    java.security »




SecureRandom