RANDOM(a, b) is the AP Computer Science Principles pseudocode function (on the exam reference sheet) that generates and returns a random integer from a to b, INCLUSIVE of both endpoints, with each possible value equally likely. For example, RANDOM(1, 3) can return 1, 2, or 3.
RANDOM(a, b) is the random-number function in AP CSP's exam pseudocode, and it's printed right on the exam reference sheet, so you never have to memorize its syntax, just its behavior. It generates and returns a random integer from a to b, inclusive on both ends, and every value in that range is equally likely. So RANDOM(1, 3) can return 1, 2, or 3, each with probability 1/3.
Two behaviors matter most. First, count the possible values carefully. RANDOM(10, 20) has 11 possible outcomes (10 through 20), not 10, because both endpoints count. Second, randomness means non-determinism. A program that uses RANDOM(a, b) can produce a different result every time it runs, even with the same code and same inputs (EK AAP-3.E.2). That's the whole point of random values in simulations and games.
RANDOM(a, b) is the core of Topic 3.15 (Random Values) in Unit 3: Algorithms and Programming. It directly supports learning objective AP Comp Sci P 3.15.A, which asks you to do two things. You write expressions that produce a desired set of possible values (like simulating a six-sided die with RANDOM(1, 6)), and you evaluate a given expression to determine all of its possible results. Randomness also connects to a bigger CED idea about program behavior. Most code is deterministic, meaning the same input always gives the same output. RANDOM breaks that rule on purpose, which is why EK AAP-3.E.2 calls out that each execution may produce a different result. That's exactly what makes simulations (Topic 3.16) possible.
Keep studying AP Computer Science Principles Unit 3
randint() (Unit 3)
Python's randint(a, b) is the real-world twin of RANDOM(a, b). Both return a random integer from a to b inclusive. If you've coded in Python, you already know how RANDOM behaves.
random module (Unit 3)
In actual Python, random functions live in the random module and have to be imported. The AP exam skips all that and hands you RANDOM(a, b) on the reference sheet, so the test is about behavior, not setup.
uniform() (Unit 3)
Python's uniform(a, b) returns a random decimal (float) in a range. RANDOM(a, b) only ever returns integers. If a question needs a whole-number outcome like a die roll, RANDOM is the right tool.
Simulations (Unit 3)
Topic 3.16 builds directly on RANDOM. A simulation models a real-world process, like coin flips or weather, by generating random values over many trials. RANDOM(a, b) is the engine that makes each trial unpredictable.
RANDOM(a, b) shows up in multiple-choice questions, and they almost always test the same two skills from 3.15.A. One type gives you an expression and asks for the set of possible values, like "a program executes val ← RANDOM(0, 4); what are the possible values of val?" (answer: the integers 0, 1, 2, 3, 4). Another type flips it and asks you to pick the expression that produces a target range. A third type mixes in probability, like "what is the probability RANDOM(1, 6) returns an even number?" Since 2, 4, and 6 are three of six equally likely outcomes, the answer is 1/2. The trap to avoid every time is treating the upper bound as exclusive. Both endpoints are included, so RANDOM(10, 20) has 11 possible values, not 10. RANDOM can also appear inside larger code segments, like RANDOM(1, 10) used in a condition, where you have to reason about which executions are possible.
The classic mistake is assuming RANDOM(a, b) excludes the upper bound, the way some real-language functions do (Python's randrange(a, b) stops at b-1). AP pseudocode's RANDOM(a, b) is inclusive on BOTH ends, just like Python's randint(a, b). On the exam, b is always a possible result. If a question about RANDOM(1, 3) doesn't include 3 as a possible output in your answer, you've picked the trap.
RANDOM(a, b) returns a random integer from a to b, and both a and b are included as possible results.
Every value in the range is equally likely, so RANDOM(1, 3) returns 1, 2, or 3 each with probability 1/3.
To count possible outcomes, use b minus a plus 1, so RANDOM(10, 20) has 11 possible values.
A program that uses RANDOM can produce a different result on each execution, even with identical code and inputs.
RANDOM(a, b) is on the exam reference sheet, so the test measures whether you can evaluate and write random expressions, not whether you memorized syntax.
RANDOM behaves like Python's randint(), not like functions where the upper bound is excluded.
It generates and returns a random integer from a to b, inclusive of both endpoints, with each value equally likely. It's defined on the AP exam reference sheet, so its exact behavior is guaranteed on every question.
Inclusive. RANDOM(1, 3) can return 1, 2, or 3, and RANDOM(10, 20) can return any of the 11 integers from 10 through 20. Treating b as excluded is the most common trap answer on these questions.
Behaviorally, yes. Both return a random integer from a to b with both endpoints included. The difference is that RANDOM is AP pseudocode given on the reference sheet, while randint() is a real Python function from the random module that you have to import.
No. RANDOM(a, b) only returns integers. If you've seen Python's uniform(a, b), that's the one that returns random decimals, and it does not exist in AP pseudocode.
1/2. RANDOM(1, 6) has six equally likely outcomes (1 through 6), and three of them (2, 4, 6) are even, so the probability is 3/6. This is exactly the kind of evaluation question learning objective 3.15.A targets.