Skip to content

Insecure Random Number Generation

Description

The rand() PRNG should not be used in applications intended to be portable when good randomness is needed. Instead, the use of random() is recommended.

Examples

Insecure Code

c
int x = rand();

Secure Code

c
int x = random();

Remediation

Replace rand() with a cryptographically secure pseudorandom number generator like random()

Rule Details

FieldValue
IDCODE-0494
CategoryCrypto
SeverityMEDIUM
CWECWE-338
ConfidenceHIGH
ImpactMEDIUM
LikelihoodMEDIUM
ExploitabilityMODERATE
Tagsrandomness, portability
OWASPN/A

References