Skip to main content

prefer-random-secure

effort: 2m
has IDE fix
has auto-fix
pro+

Warns when Random is used in a security-sensitive context.

The output of Random is predictable and must not be used in security-sensitive contexts.

Example

❌ Bad:

void fn() {
// LINT: The output of Random is predictable and must not be used in security-sensitive contexts.
// Try using 'Random.secure()' instead.
final random = Random();
}

✅ Good:

void fn() {
final random = Random.secure();
}

Additional Resources