Java API Tutorial - 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.

//www  .jav  a 2s . 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));
  }
}

The code above generates the following result.