Java API Tutorial - Java SecureRandom .getInstance (String algorithm, String provider)








Syntax

SecureRandom.getInstance(String algorithm, String provider) has the following syntax.

public static SecureRandom getInstance(String algorithm,    String provider)    throws NoSuchAlgorithmException ,      NoSuchProviderException

Example

In the following code shows how to use SecureRandom.getInstance(String algorithm, String provider) method.

import java.security.SecureRandom;
//from w w w  .  j  av  a2  s .  c  o  m
public class Main {
  public static void main(String args[]) throws Exception {
    SecureRandom ran = SecureRandom.getInstance("SHA1PRNG", "SUN");
    ran.setSeed(101L);
    ran.setSeed(101L);
    byte[] seeds = ran.getSeed(24);
    for (int i = 0; i < seeds.length; i++) {
      System.out.println("Seed[" + i + "]:" + seeds[i]);
    }
  }
}
   

The code above generates the following result.