Insufficiently random generators or hardcoded seeds can make pseudorandom sequences predictable, which may lead to security vulnerabilities.
1static void secureRandomSpecificAlgorithmNoncompliant() throws Exception {
2 final String ALGORITHM_NAME = "DES";
3 // Noncompliant: one specific algorithm is requested.
4 SecureRandom generator = SecureRandom.getInstance(ALGORITHM_NAME);
5 System.out.println(generator.nextInt());
6}
1static void secureRandomDefaultCompliant() throws Exception {
2 // Compliant: no specific algorithm is requested.
3 SecureRandom generator = new SecureRandom();
4 System.out.println(generator.nextInt());
5}