Using pseudorandom number generators (PRNGs) is security-sensitive. For example, it has led in the past to the following vulnerabilities:

When software generates predictable values in a context requiring unpredictability, it may be possible for an attacker to guess the next value that will be generated, and use this guess to impersonate another user or access sensitive information.

Ask Yourself Whether

There is a risk if you answered yes to any of those questions.

Recommended Secure Coding Practices

Sensitive Code Example

val random = Random() // Noncompliant: Random() is not a secure random number generaotr
val bytes = ByteArray(20)
random.nextBytes(bytes)

Compliant Solution

val random = SecureRandom() // Compliant
val bytes = ByteArray(20)
random.nextBytes(bytes)

See