SecureRandom: getInstance(String algorithm) throws NoSuchAlgorithmException
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
public class Main {
public static void main(String[] args) throws NoSuchAlgorithmException {
int numBytes = (new Integer("1111")).intValue();
long seed = 01;
if (args.length > 1)
seed = (new Long("1111111111")).longValue();
SecureRandom srand = SecureRandom.getInstance("SHA1PRNG");
if (seed != 01)
srand.setSeed(seed);
byte[] bytes = new byte[numBytes];
srand.nextBytes(bytes);
System.out.println(new String(bytes));
}
}
Related examples in the same category