SecureRandom.getInstance(String algorithm, Provider provider) has the following syntax.
public static SecureRandom getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException
In the following code shows how to use SecureRandom.getInstance(String algorithm, Provider provider) method.
//from w ww . ja va 2 s . c om import java.security.NoSuchAlgorithmException; import java.security.Provider; import java.security.SecureRandom; public class Main { public static void main(String[] args) throws NoSuchAlgorithmException { int numBytes = (new Integer("1111")).intValue(); SecureRandom srand = new SecureRandom(new byte[]{1,2,3,4}); Provider provider = srand.getProvider(); SecureRandom newRandom = SecureRandom.getInstance("SHA1PRNG",provider); System.out.println(provider.getName()); byte[] bytes = new byte[numBytes]; srand.nextBytes(bytes); System.out.println(bytes); } }
The code above generates the following result.