Skip to content

Commit

Permalink
RandomExample : SecureRandom
Browse files Browse the repository at this point in the history
Use NativePRNGNonBlocking in SecureRandom

Signed-off-by: neojou <neojou@gmail.com>
  • Loading branch information
neojou committed Dec 7, 2022
1 parent cbe6fb1 commit 3cfe649
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions RandomExample/src/Main.java
@@ -1,4 +1,5 @@

import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.util.function.IntUnaryOperator;
import java.util.IntSummaryStatistics;
Expand Down Expand Up @@ -32,13 +33,16 @@ public static void main(String[] args) {
System.out.println();

// SecureRandom
SecureRandom srnd = new SecureRandom();
System.out.println("default secure random algorithm = " + srnd.getAlgorithm());
for (int i = 0; i < 10; i++) {
r = 10 + srnd.nextInt(100 - 10 + 1);
System.out.print(" " + r);
try {
SecureRandom srnd = SecureRandom.getInstance("NativePRNGNonBlocking");
System.out.println("current random algorithm = " + srnd.getAlgorithm());
for (int i = 0; i < 10; i++) {
r = 10 + srnd.nextInt(100 - 10 + 1);
System.out.print(" " + r);
}
System.out.println();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
System.out.println();

}
}

0 comments on commit 3cfe649

Please sign in to comment.