Pseudorandom value in AP Computer Science A

In AP Computer Science A, a pseudorandom value is a number produced by a deterministic algorithm (like Math.random()) that looks random but is actually computed. Math.random() returns a pseudorandom double from 0.0 (inclusive) up to but not including 1.0, which you scale and shift to get other ranges.

Verified for the 2027 AP Computer Science A examLast updated June 2026

What is pseudorandom value?

A pseudorandom value is a number that looks random but isn't truly random. It's produced by an algorithm following fixed mathematical steps. Computers can't flip real coins, so they fake it: an algorithm crunches a starting number (a seed) through a formula and spits out values that are spread out unpredictably enough to act random for your purposes.

In AP CSA, the pseudorandom value you care about comes from Math.random(), a static method in the Math class (which lives in java.lang, so it's available by default with no import). It returns a double greater than or equal to 0.0 and strictly less than 1.0. On its own that's not super useful, so you transform it. (int)(Math.random() * 6) + 1 simulates a die roll. The pattern is multiply to set the range size, add to shift the starting point, and cast to int to chop off the decimal.

Why pseudorandom value matters in AP® Computer Science A

Pseudorandom values live in Topic 1.11 (Using the Math Class) in Unit 1: Using Objects and Methods, under learning objective 1.11.A, which asks you to write expressions using built-in math libraries and determine the values they produce. Math.random() is one of the Math class methods listed in the Java Quick Reference, so the College Board hands you its signature on the exam but expects you to know how to use it.

The real skill being tested isn't randomness trivia. It's whether you can reason about ranges. Given (int)(Math.random() * 10) + 5, can you say the result is an integer from 5 to 14, inclusive? That kind of expression-evaluation question is exactly what 1.11.A targets, and the random-range formula shows up again any time later code needs a simulated coin flip, dice roll, or random index.

How pseudorandom value connects across the course

Math.random() (Unit 1)

Math.random() is THE source of pseudorandom values in AP CSA. It's a static method, so you call it on the class itself, never on an object. Every random-range trick on the exam starts with this one method returning a double in [0.0, 1.0).

Random number generation and range formulas (Unit 1)

The exam payoff is turning a raw pseudorandom double into a useful integer range. Memorize the template (int)(Math.random() * range) + min, where range is how many possible values you want and min is the smallest one. Read it backwards to decode someone else's expression.

Casting and integer truncation (Unit 1)

The (int) cast in random expressions truncates toward zero, it does not round. That's why (int)(Math.random() * 6) gives 0 through 5 and never 6. Mixing up truncation and rounding is one of the easiest ways to be off by one on an MCQ.

Static methods and the Math class (Unit 1)

The Math class contains only class (static) methods, per EK 1.11.A.2. Math.random() reinforces the bigger Unit 1 idea that some methods belong to the class, not to instances, so you write Math.random(), not new Math().

Is pseudorandom value on the AP® Computer Science A exam?

This concept shows up in multiple-choice questions built on learning objective 1.11.A. A typical stem gives you an expression like (int)(Math.random() * 20) + 10 and asks for the range of possible values, or describes a target range (say, integers 3 through 8) and asks which expression produces it. You need to identify both endpoints correctly and remember which one is inclusive. The full range of a random expression includes both the minimum and the maximum integer after truncation.

No released FRQ has used the phrase "pseudorandom value" verbatim, but FRQs regularly require a line of code that picks a random element, simulates a chance event, or generates a value in a range. Writing the scale-shift-cast expression correctly is a real point on the table. Practice converting both directions: expression to range, and range to expression.

Pseudorandom value vs truly random value

A truly random value comes from an unpredictable physical process. A pseudorandom value comes from a deterministic algorithm, meaning the same starting conditions produce the same sequence every time. Math.random() is pseudorandom. It just does such a good job of looking random that it works fine for simulations and games, which is all AP CSA asks of it.

Key things to remember about pseudorandom value

  • A pseudorandom value is computed by a deterministic algorithm but appears random, and in Java you get one from Math.random().

  • Math.random() returns a double that is greater than or equal to 0.0 and strictly less than 1.0, so 1.0 itself is never returned.

  • To get a random integer from min to max inclusive, use (int)(Math.random() * (max - min + 1)) + min.

  • The (int) cast truncates the decimal part instead of rounding, which is why the multiplier value itself is never reached.

  • Math.random() is a static method in the Math class, part of java.lang, so it needs no import and is called on the class, not an object.

  • On the exam, the core skill is determining the exact range of values an expression with Math.random() can produce, including both endpoints.

Frequently asked questions about pseudorandom value

What is a pseudorandom value in AP Computer Science A?

It's a value generated by an algorithm, like Math.random(), that appears random but is deterministically computed. In AP CSA it's covered in Topic 1.11 under learning objective 1.11.A, and Math.random() returns a pseudorandom double in the range [0.0, 1.0).

Can Math.random() ever return 1.0?

No. Math.random() returns a double greater than or equal to 0.0 and strictly less than 1.0. That's why (int)(Math.random() * 6) gives 0 through 5, never 6.

Is Math.random() actually random?

No, it's pseudorandom. An algorithm computes each value deterministically from internal state, so it only simulates randomness. For everything AP CSA asks (dice rolls, random indexes, simulations), that's good enough.

How do I get a random integer between two numbers in Java?

Use (int)(Math.random() * (max - min + 1)) + min. For example, (int)(Math.random() * 6) + 1 produces an integer from 1 to 6, like rolling a standard die.

What's the difference between Math.random() and other Math class methods like Math.pow()?

Math.pow(), Math.sqrt(), and Math.abs() take input and return a predictable result, while Math.random() takes no parameters and returns a different pseudorandom double each call. All of them are static methods in the Math class listed in the Java Quick Reference.