Insufficiently random generators or hardcoded seeds can make pseudorandom sequences predictable, which may lead to security vulnerabilities.
1// Noncompliant: `Random()` is not a secure random number generator
2fun noncompliant() {
3 val random = Random()
4 val bytes = ByteArray(20)
5 random.nextBytes(bytes)
6}
1// Compliant: Using `SecureRandom()` to generate random numbers
2fun compliant() {
3 val random = SecureRandom()
4 val bytes = ByteArray(20)
5 random.nextBytes(bytes)
6}