Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V5307. OWASP. Potentially...
menu mobile close menu
Additional information
toggle menu Contents

V5307. OWASP. Potentially predictable seed is used in pseudo-random number generator.

Sep 26 2024

The analyzer has detected cases where a pseudo-random number generator is used. It may result in insufficient randomness or predictability of the generated number.

Case 1

A new object of the 'Random' type is created every time when a random value is required. This is inefficient and may result in creating numbers that are not random enough depending on the JDK.

Look at an example:

public void test() {
  Random rnd = new Random();
}

For better efficiency and a more random distribution, create an instance of the 'Random' class, save and reuse it.

static Random rnd = new Random();

public void test() {
  int i = rnd.nextInt();
}

Case 2

The analyzer has detected a suspicious code that initializes the pseudo-random number generator with a constant value.

public void test() {
  Random rnd = new Random(4040);
}

Generated numbers are predictable. They are repeated every time the program runs. To avoid this, do not use a constant number. The developers may have used the current system time instead:


static Random rnd = new Random(System.currentTimeMillis());

public void test() {
  int i = rnd.nextInt();
}

This diagnostic is classified as:

close form

Fill out the form in 2 simple steps below:

Your contact information:

Step 1
Congratulations! This is your promo code!

Desired license type:

Step 2
Team license
Enterprise license
close form
Request our prices
New License
License Renewal
--Select currency--
USD
EUR
close form
Free PVS‑Studio license for Microsoft MVP specialists
close form
To get the licence for your open-source project, please fill out this form
close form
I want to join the test
* By clicking this button you agree to our Privacy Policy statement

close form
check circle
Message submitted.

Your message has been sent. We will email you at


If you do not see the email in your inbox, please check if it is filtered to one of the following folders:

  • Promotion
  • Updates
  • Spam