BAEL-3001

This commit is contained in:
Krzysztof Majewski 2019-07-03 20:06:46 +02:00
parent 55c9579875
commit 9b4f63704a
1 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,36 @@
package com.baeldung.random;
import java.security.SecureRandom;
import java.security.NoSuchAlgorithmException;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.util.stream.DoubleStream;
public interface SecureRandomDemo {
public static void generateSecureRandomValues() {
SecureRandom sr = new SecureRandom();
int randomInt = sr.nextInt();
long randomLong = sr.nextLong();
float randomFloat = sr.nextFloat();
double randomDouble = sr.nextDouble();
boolean randomBoolean = sr.nextBoolean();
IntStream randomIntStream = sr.ints();
LongStream randomLongStream = sr.longs();
DoubleStream randomDoubleStream = sr.doubles();
byte[] values = new byte[124];
sr.nextBytes(values);
}
public static SecureRandom getSecureRandomForAlgorithm(String algorithm) throws NoSuchAlgorithmException {
if (algorithm == null || algorithm.isEmpty()) {
return new SecureRandom();
}
return SecureRandom.getInstance(algorithm);
}
}