...
Code Block | ||
---|---|---|
| ||
import java.security.SecureRandom; import java.security.NoSuchAlgorithmException; // ... public static void main (String args[]) { try { SecureRandom number = SecureRandom.getInstance ("SHA1PRNG"); // generate 20 integers 0..20 for (int i=0; i<20; i++) { System.out.println(number.nextInt(21)); } } catch (NoSuchAlgorithmException nsae) { /* handle */ } } |
Exceptions
MSC30-EX1: Using a null seed value (as opposed to reusing it) may improve security marginally but should only be used for non-critical applications. Java's default seed uses the system's time in milliseconds. This exception is not recommended for applications requiring high security (for instance, session IDs should not use this). When used, explicit documentation of this exception is encouraged.
...