Security

What is Same Seed in Pseudo-Random Number (CWE-336)?

Learn how same seed in pseudo-random number generator (PRNG) vulnerabilities work, see real-world code examples, and discover framework-specific fixes to...

SP
Shreya Pillai July 29, 2026 5 min read Security
AI-friendly summary

What it is: Same Seed in Pseudo-Random Number Generator (PRNG) (CWE-336) is a type of cryptographic failure that occurs when a PRNG uses the same seed each time it initializes.

Why it matters: This vulnerability allows attackers to predict future outputs, compromising security mechanisms such as encryption keys and session tokens.

How to fix it: Ensure that PRNGs are re-seeded with high-quality entropy from trusted sources like hardware devices.

TL;DR: Same Seed in Pseudo-Random Number Generator (PRNG) is a cryptographic failure where the same seed is used for each initialization, leading to predictable sequences. Fix it by ensuring PRNGs use high-quality entropy.

Field Value
CWE ID CWE-336
OWASP Category A04:2025 - Cryptographic Failures
CAPEC None known
Typical Severity High
Affected Technologies Python, Java, Node.js, PHP
Detection Difficulty Moderate
Last Updated 2026-07-29

What is Same Seed in Pseudo-Random Number Generator (PRNG)?

Same Seed in Pseudo-Random Number Generator (PRNG) (CWE-336) is a type of cryptographic failure that occurs when a pseudo-random number generator uses the same seed each time it initializes. As defined by the MITRE Corporation under CWE-336, and classified by the OWASP Foundation under A04:2025 Cryptographic Failures.

Quick Summary

Same Seed in Pseudo-Random Number Generator (PRNG) is a serious cryptographic vulnerability that can lead to predictable sequences of random numbers. This reduces security mechanisms like encryption keys and session tokens to known values, making them vulnerable to attacks. Jump to: Overview · How It Works · Business Impact · Attack Scenario · Detection · Fixes

Jump to: Quick Summary · Same Seed in Pseudo-Random Number Generator (PRNG) Overview · How Same Seed in Pseudo-Random Number Generator (PRNG) Works · Business Impact of Same Seed in Pseudo-Random Number Generator (PRNG) · Same Seed in Pseudo-Random Number Generator (PRNG) Attack Scenario · How to Detect Same Seed in Pseudo-Random Number Generator (PRNG) · How to Fix Same Seed in Pseudo-Random Number Generator (PRNG) · Framework-Specific Fixes for Same Seed in Pseudo-Random Number Generator (PRNG) · How to Ask AI to Check Your Code for Same Seed in Pseudo-Random Number Generator (PRNG) · Same Seed in Pseudo-Random Number Generator (PRNG) Best Practices Checklist · Same Seed in Pseudo-Random Number Generator (PRNG) FAQ · Vulnerabilities Related to Same Seed in Pseudo-Random Number Generator (PRNG) · References · Scan Your Own Site

Same Seed in Pseudo-Random Number Generator (PRNG) Overview

What

Same Seed in Pseudo-Random Number Generator (PRNG) is a cryptographic failure where the same seed value is used for each initialization of a PRNG, leading to predictable sequences.

Why it matters

This vulnerability allows attackers to predict future outputs and bypass security mechanisms that rely on randomness. It can lead to data breaches, loss of confidentiality, and compromised security features like encryption keys and session tokens.

Where it occurs

It commonly affects applications that use pseudo-random number generators without proper entropy sources or re-seeding mechanisms.

Who is affected

Developers using PRNGs in cryptographic contexts, such as generating secure keys, salts, and nonces.

Who is NOT affected

Applications that properly seed their PRNG with high-quality randomness from trusted hardware devices or FIPS 140-2 compliant modules.

How Same Seed in Pseudo-Random Number Generator (PRNG) Works

Root Cause

The root cause lies in the improper initialization of a pseudo-random number generator, where the same seed is used repeatedly without re-seeding with high-quality entropy.

Attack Flow

  1. Attacker identifies that the PRNG uses a static or predictable seed.
  2. The attacker predicts future outputs by analyzing past sequences.
  3. Predicted values are used to compromise security mechanisms relying on randomness.

Prerequisites to Exploit

  • Static or predictable seed initialization.
  • Lack of re-seeding with high-quality entropy sources.

Vulnerable Code

import random

seed_value = 12345  # Hardcoded static value
random.seed(seed_value)

This code initializes the PRNG with a fixed seed, making it vulnerable to prediction attacks.

Secure Code

import os
import random

# Use high-quality entropy from OS
seed_value = int.from_bytes(os.urandom(4), byteorder='big')
random.seed(seed_value)

The secure version uses high-quality entropy from the operating system for re-seeding, ensuring unpredictability.

Business Impact of Same Seed in Pseudo-Random Number Generator (PRNG)

Confidentiality

Data confidentiality is compromised as encryption keys and session tokens can be predicted and used to decrypt data or hijack sessions.

Integrity

Integrity mechanisms relying on random values may fail if attackers predict future outputs, leading to unauthorized modifications.

Same Seed in Pseudo-Random Number Generator (PRNG) Attack Scenario

  1. Attacker identifies the static seed value used by the PRNG.
  2. Analyzes past sequences to predict future outputs.
  3. Uses predicted values to decrypt encrypted data or hijack sessions.

How to Detect Same Seed in Pseudo-Random Number Generator (PRNG)

Manual Testing

  • Review code for hardcoded seed values.
  • Check if re-seeding mechanisms are properly implemented.
  • Ensure PRNGs use high-quality entropy sources like hardware devices.

Automated Scanners (SAST / DAST)

Static analysis can detect hardcoded seeds, while dynamic testing can verify proper re-seeding and randomness quality.

PenScan Detection

PenScan’s scanner engines ZAP, Nuclei, Wapiti, Nikto, SSLyze, Dalfox, and Nmap can identify PRNG vulnerabilities during automated scans.

False Positive Guidance

False positives may occur if the code uses non-predictable seed values or re-seeds properly. Verify that the seed is not static or predictable before marking as a false positive.

How to Fix Same Seed in Pseudo-Random Number Generator (PRNG)

  • Do not reuse PRNG seeds.
  • Consider using PRNGs that periodically re-seed themselves with high-quality entropy from hardware devices.
  • Use products or modules conforming to FIPS 140-2 standards for secure random number generation.

Framework-Specific Fixes for Same Seed in Pseudo-Random Number Generator (PRNG)

Python

import os
import random

# Use high-quality entropy from OS
seed_value = int.from_bytes(os.urandom(4), byteorder='big')
random.seed(seed_value)

Java

import java.security.SecureRandom;

SecureRandom secureRandom = new SecureRandom();
secureRandom.nextBytes(new byte[20]);  // Use high-quality entropy from OS

Node.js

const crypto = require('crypto');

let seedValue = crypto.randomInt(1, Number.MAX_SAFE_INTEGER);
crypto.seed(seedValue);

PHP

$seed_value = random_int(PHP_INT_MIN, PHP_INT_MAX);  // Use high-quality entropy from OS
mt_srand($seed_value);

How to Ask AI to Check Your Code for Same Seed in Pseudo-Random Number Generator (PRNG)

Copy-paste prompt

Review the following [language] code block for potential CWE-336 Same Seed in Pseudo-Random Number Generator (PRNG) vulnerabilities and rewrite it using high-quality entropy: [paste code here]

Same Seed in Pseudo-Random Number Generator (PRNG) Best Practices Checklist

✅ Do not reuse PRNG seeds. ✅ Use products or modules conforming to FIPS 140-2 standards for secure random number generation. ✅ Periodically re-seed PRNGs with high-quality entropy from hardware devices.

Same Seed in Pseudo-Random Number Generator (PRNG) FAQ

How does same seed in pseudo-random number generator (PRNG) occur?

It occurs when a PRNG uses the same seed each time it is initialized, leading to predictable sequences of random numbers.

Why is same seed in pseudo-random number generator (PRNG) dangerous?

It allows attackers to predict future outputs and bypass security mechanisms that rely on randomness.

How can I detect same seed in pseudo-random number generator (PRNG)?

Use static analysis tools or manual code reviews to check for hardcoded seeds or predictable initialization methods.

What is the primary fix for same seed in pseudo-random number generator (PRNG)?

Ensure that PRNGs are re-seeded with high-quality entropy from trusted sources like hardware devices.

Use libraries or modules conforming to FIPS 140-2 standards for secure random number generation.

What are the business impacts of same seed in pseudo-random number generator (PRNG)?

It can lead to data breaches, loss of confidentiality, and compromised security mechanisms.

How does OWASP classify same seed in pseudo-random number generator (PRNG)?

CWE-336 is classified under A04:2025 Cryptographic Failures by the OWASP Foundation.

CWE Name Relationship
CWE-335 Incorrect Usage of Seeds in Pseudo-Random Number Generator (PRNG) ChildOf

References

Scan Your Own Site

Manual code review catches what you know to look for. An automated scan catches what you didn’t. Scan your own website using PenScan to find Same Seed in Pseudo-Random Number Generator (PRNG) and other risks before an attacker does.