# VNX-1241: Use of Predictable Algorithm in Random Number Generator

A java.util.Random, whose linear congruential algorithm is fully determined by its 48-bit seed, is given an explicit seed in production Java code.

| Field | Value |
|---|---|
| Rule ID | `VNX-1241` |
| Severity | Medium |
| SARIF level | `warning` |
| Kind | `sast` |
| Languages | Java |
| CWE | [CWE-1241](https://cwe.mitre.org/data/definitions/1241.html) |
| CAPEC | [CAPEC-66](https://capec.mitre.org/data/definitions/66.html) |
| ATT&CK | [T1190](https://attack.mitre.org/techniques/T1190/) |
| CWSS vector | `CWSS:1.0/TI:M/AP:RU/AL:S/IC:N/FC:LT/RP:RU/RL:S/AV:L/AS:N/IN:A/SC:A/BI:M/DI:H/EX:M/EC:N/P:C` |
| Tags | `predictable-rng` `java` `cwe-1241` |
| Source | [`internal/sast/rules/vnx-1241.rego`](https://github.com/Vulnesis/cli/blob/main/internal/sast/rules/vnx-1241.rego) |

## Overview

VNX-1241 maps to [CWE-1241: Use of Predictable Algorithm in Random Number Generator](https://cwe.mitre.org/data/definitions/1241.html).

## Why this matters

`java.util.Random` is a 48-bit linear congruential generator. Its whole output follows from the seed, so a generator seeded with a constant, the clock or a value derived from user data produces values anyone can reproduce. Reset links, session ids and OTPs drawn from it can be predicted.

## What gets flagged

```java
private final Random rng = new Random(42L);
Random random = new Random(System.currentTimeMillis());
random.setSeed(key.length());      // random declared as java.util.Random
```

Not flagged: `new Random()` with no seed, `SecureRandom` and its `setSeed`, a method of your own named `setSeed`, test code.

## Remediation

1. Use `java.security.SecureRandom` for any value an attacker must not predict, and do not seed it yourself.
2. Keep seeded `java.util.Random` for simulations and tests only.

## References

- [CWE-1241: Use of Predictable Algorithm in Random Number Generator](https://cwe.mitre.org/data/definitions/1241.html)

## Suppressing this rule

Put a `nosec` comment on the line, or on line 1 to cover the whole file. Use the comment marker of the file's language (`#`, `//`, `--` or `;`):

```text
# nosec vnx-1241
// nosec vnx-1241
```

Or record an ignore rule: `vulnetix ignore add --rule vnx-1241 --reason "..."`. See [Suppressing findings](/sast/guides/suppressing-findings.md).
