---
title: "CWE-338: Use of Cryptographically Weak Pseudo-Random Number Generator (PRNG)"
url: https://radicalnotion.ai/cwe/cwe-338
type: cwe
description: "The product uses a Pseudo-Random Number Generator (PRNG) in a security context, but the PRNG's algorithm is not cryptographically strong."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-338: Use of Cryptographically Weak Pseudo-Random Number Generator (PRNG)

- **Abstraction:** Base
- **Structure:** Simple
- **Status:** Draft
- **Likelihood of exploit:** Medium
- **CVEs with this as primary weakness:** 198
- **Of those, in CISA KEV:** 0
- **New in 2026:** 68
- **CWE catalog version:** 4.21

## Description

The product uses a Pseudo-Random Number Generator (PRNG) in a security context, but the PRNG's algorithm is not cryptographically strong.

When a non-cryptographic PRNG is used in a cryptographic context, it can expose the cryptography to certain types of attacks.

Often a pseudo-random number generator (PRNG) is not designed for cryptography. Sometimes a mediocre source of randomness is sufficient or preferable for algorithms that use random numbers. Weak generators generally take less processing power and/or do not use the precious, finite, entropy sources on a system. While such PRNGs might have very useful features, these same features could be used to break the cryptography.

## Modes of introduction

| Phase | Note |
| --- | --- |
| Architecture and Design | - |
| Implementation | REALIZATION: This weakness is caused during implementation of an architectural security tactic. |

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Access Control | Bypass Protection Mechanism | If a PRNG is used for authentication and authorization, such as a session ID or a seed for generating a cryptographic key, then an attacker may be able to easily guess the ID or cryptographic key and gain access to restricted functionality. |

## Potential mitigations

### Implementation

Use functions or hardware which use a hardware-based random number generation for all crypto. This is the recommended solution. Use CyptGenRandom on Windows, or hw\_rand() on Linux.

## Detection methods

### Automated Static Analysis

Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)

Effectiveness: High

## Demonstrative examples

### Example 1

Both of these examples use a statistical PRNG seeded with the current value of the system clock to generate a random number:

Bad code:

```java
Random random = new Random(System.currentTimeMillis());
int accountID = random.nextInt();
```

Bad code:

```c
srand(time());
int randNum = rand();
```

The random number functions used in these examples, rand() and Random.nextInt(), are not considered cryptographically strong. An attacker may be able to predict the random numbers generated by these functions. Note that these example also exhibit CWE-337 (Predictable Seed in PRNG).

## Observed examples

| CVE | Description |
| --- | --- |
| CVE-2021-3692 | PHP framework uses mt\_rand() function (Marsenne Twister) when generating tokens |
| CVE-2009-3278 | Crypto product uses rand() library function to generate a recovery key, making it easier to conduct brute force attacks. |
| CVE-2009-3238 | Random number generator can repeatedly generate the same value. |
| CVE-2009-2367 | Web application generates predictable session IDs, allowing session hijacking. |
| CVE-2008-0166 | SSL library uses a weak random number generator that only generates 65,536 unique keys. |

## Real CVEs with this weakness (sample of 12 of 198)

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2026-79901 | Predictable Active Directory service-account passwords in BoKS Manager | critical | 9.9 | - | No | 2026-10-01 |
| CVE-2026-9205 | Langflow is affected by weaknesses in secret handling and sensitive configuration access | critical | 9.8 | - | No | 2026-08-05 |
| CVE-2026-16235 | Crypt::Password versions through 0.28 for Perl generate insecure random values for salts | critical | 9.8 | - | No | 2026-07-20 |
| CVE-2026-56141 | - | critical | 9.8 | - | No | 2026-06-19 |
| CVE-2026-25726 | Cloudreve is vulnerable to Account Takeover via Weak Cryptographic Token Generation (Insecure PRNG Seeding) | critical | 9.8 | - | No | 2026-04-03 |
| CVE-2025-15578 | Maypole versions from 2.10 through 2.13 for Perl generates session ids insecurely | critical | 9.8 | - | No | 2026-02-16 |
| CVE-2025-59390 | Apache Druid: Kerberos authenticaton chooses a cryptographically unsecure secret if not configured explicitly. | critical | 9.8 | - | No | 2025-11-26 |
| CVE-2025-3495 | COMMGR - Insufficient Randomization Authentication Bypass | critical | 9.8 | - | No | 2025-04-16 |
| CVE-2024-40762 | SonicWALL NSv Cryptographically Weak PRNG Authentication Bypass Vulnerability | critical | 9.8 | - | No | 2025-01-09 |
| CVE-2023-36993 | - | critical | 9.8 | - | No | 2023-07-07 |
| CVE-2023-2884 | Insecure Randomness in CBOT's Chatbot | critical | 9.8 | - | No | 2023-05-25 |
| CVE-2022-44796 | - | critical | 9.8 | - | No | 2022-11-07 |

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-330](https://radicalnotion.ai/cwe/cwe-330) | Use of Insufficiently Random Values |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| CLASP | Non-cryptographic PRNG | - | - |
| CERT C Secure Coding | Do not use the rand() function for generating pseudorandom numbers | MSC30-C | CWE More Abstract |

## Frequently asked questions

### What is CWE-338?

The product uses a Pseudo-Random Number Generator (PRNG) in a security context, but the PRNG's algorithm is not cryptographically strong.

### What CVEs are caused by CWE-338?

198 recorded CVEs are attributed to CWE-338, including CVE-2026-79901, CVE-2026-9205 and CVE-2026-16235.

### How do you prevent CWE-338?

Use functions or hardware which use a hardware-based random number generation for all crypto. This is the recommended solution. Use CyptGenRandom on Windows, or hw\_rand() on Linux.

### How is CWE-338 detected?

Automated Static Analysis: Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)

### What are the consequences of CWE-338?

Exploiting CWE-338 can lead to: Bypass Protection Mechanism.

### Is CWE-338 actively exploited?

198 recorded CVEs are caused by CWE-338; none are currently in CISA's KEV catalog of actively exploited flaws.

Primary source: [MITRE CWE](https://cwe.mitre.org/data/definitions/338.html)

---

Source: [RadicalNotion.AI](https://radicalnotion.ai/cwe/cwe-338). Licensed CC BY-NC 4.0; attribute RadicalNotion.AI and link the source page when you reuse this data.
