In CBSE 083 probable-output questions, `random.randint(a, b)` returns an integer `N` with BOTH endpoints included (`a <= N <= b`), whereas `random.randrange(start, stop, step)` excludes `stop` (`start <= N < stop`) just like `range()`. `random.random()` produces a float in `[0.0, 1.0)`. To find minimum and maximum possible outputs, substitute each `random` call's lowest and highest legal integer separately, then check whether the output options violate parity, step, or loop bounds.
- 1. Exact Boundary Rules for random(), randint(), and randrange()
- 2. Step-by-Step Min/Max Elimination Method for Board PYQs
- 3. Deterministic Testing with random.seed() and Subtle PYQ Traps
- 4. Exhaustive Bound Checker for CBSE 083 Random Output PYQs
- 5. CBSE 083 Random Functions Quick Reference
- 6. Common Mistakes & Top Scorer Tips
- 7. Interactive Concept Check Quiz
- 8. Frequently Asked Questions
1. Exact Boundary Rules for random(), randint(), and randrange()
Nearly every wrong choice in a CBSE `random` module PYQ relies on confusing inclusive and exclusive endpoints. Specifically, `random.randint(1, 5)` can return `1, 2, 3, 4,` or `5`, making it equivalent to `random.randrange(1, 6)`. Conversely, `random.randrange(1, 5)` can return only `1, 2, 3,` or `4`, never `5`. With a single argument, `random.randrange(4)` defaults `start` to `0` and selects from `{0, 1, 2, 3}`. When a third `step` argument appears, such as `random.randrange(2, 11, 2)`, Python selects only from `{2, 4, 6, 8, 10}`—every odd integer is impossible regardless of range width. Finally, `random.random()` returns a float strictly less than `1.0`, so `int(random.random() * 4)` yields `{0, 1, 2, 3}`, never `4`. Memorizing these interval conventions eliminates guesswork on 2-mark board questions.
- `randint(a, b)` includes both `a` and `b`; `a > b` raises `ValueError`.
- `randrange(start, stop, step)` excludes `stop` and enforces `(n - start) % step == 0`.
- `random.random()` never reaches `1.0`, so `int(random.random() * N)` caps at `N - 1`.
2. Step-by-Step Min/Max Elimination Method for Board PYQs
Classic CBSE 083 questions ask two linked parts: first, which of the four printed sequences `(i)` through `(iv)` are possible outputs, and second, what are the minimum and maximum values assigned to variables like `low` and `high`. To solve systematically, list the exact legal set for every `random` expression before looking at the loop. Suppose a loop picks `k = random.randint(0, 2)` and prints `arr[k]` across three iterations, or initializes `start = random.randint(1, 3)` and runs `for i in range(start, 5):`. Notice that `start` sets the minimum loop index: if `start` ranges from `1` to `3`, the printed values can start at `arr[1]`, `arr[2]`, or `arr[3]`, but can never include `arr[0]`. Eliminate any option containing out-of-range elements, wrong step gaps, or duplicate positions when `random.sample()` or shrinking bounds prevent repetition.
- Write the full candidate set `{...}` next to each `randint`/`randrange` line on the question paper.
- Check whether the loop bound is fixed (`range(start, 5)`) or random on each iteration.
- Remember `randint` and `randrange` can repeat the same value on consecutive loop iterations.
3. Deterministic Testing with random.seed() and Subtle PYQ Traps
While real runs of `random` vary every time, calling `random.seed(value)` initializes the underlying Mersenne Twister generator to a deterministic sequence—handy for verifying your own board-exam solutions in Python without surprises. Watch out for two classic traps in CBSE papers. First, `randrange` used inside `for i in range(4):` with a variable limit such as `low = random.randint(1, 2)` and `high = random.randint(3, 5)` does not guarantee strict ordering unless `low < high` is enforced, though here `max(low) = 2 < min(high) = 3` ensures validity. Second, if a question calculates `mid = random.randint(1, 3) * 10`, remember that scaling by `10` restricts outputs exclusively to `{10, 20, 30}`—values like `15` or `25` are impossible even though they fall between `10` and `30`.
- `random.seed(k)` makes `randint` and `randrange` reproducible for debugging.
- Check arithmetic multipliers (`* 10`, `+ 5`) after finding the raw random bounds.
- Verify `min` and `max` of dependent variables independently—do not assume both hit min simultaneously unless coupled.
4. Exhaustive Bound Checker for CBSE 083 Random Output PYQs
import random
colors = ["RED", "BLUE", "GREEN", "GOLD", "PINK"]
start_choices = list(range(1, 2 + 1)) # randint(1, 2) -> [1, 2]
stop_choices = list(range(3, 6)) # randrange(3, 6) -> [3, 4, 5]
possible_outputs = []
for s in start_choices:
for e in stop_choices:
seq = "#".join(colors[i] for i in range(s, e)) + "#"
possible_outputs.append(seq)
print("Min start:", min(start_choices), "Max start:", max(start_choices))
print("Min stop:", min(stop_choices), "Max stop:", max(stop_choices))
print("All valid outputs:")
for item in possible_outputs:
print(" " + item)
candidate = "BLUE#GREEN#GOLD#"
print("Is candidate valid?", candidate in possible_outputs)
Verified Console / Dry-Run Output:
Min start: 1 Max start: 2
Min stop: 3 Max stop: 5
All valid outputs:
BLUE#GREEN#
BLUE#GREEN#GOLD#
BLUE#GREEN#GOLD#PINK#
GREEN#
GREEN#GOLD#
GREEN#GOLD#PINK#
Is candidate valid? True
5. CBSE 083 Random Functions Quick Reference
| Function Call | Endpoint Rule | Exact Possible Values | Common Board Trap |
|---|---|---|---|
| random.randint(1, 5) | Both 1 and 5 included | 1, 2, 3, 4, 5 | Thinking 5 is excluded like range() |
| random.randrange(1, 5) | 1 included, 5 excluded | 1, 2, 3, 4 | Thinking 5 can be generated |
| random.randrange(2, 10, 2) | Step 2, 10 excluded | 2, 4, 6, 8 | Picking odd values or 10 |
| random.random() | 0.0 <= x < 1.0 | Floats in [0.0, 1.0) | Assuming 1.0 can be returned |
Ace Every CBSE 083 Random Output Question
Solve 50+ curated CBSE Class 12 CS 083 probable-output PYQs with live trace walkthroughs at 4Achievers Junior (Grades 3-12, 1-on-1 & 1:4 Micro-Pods). Book a free 1:1 trial class.
6. Common Mistakes & Top Scorer Tips
- Avoid Mistake: Treating `random.randint(a, b)` as excluding `b`, or treating `random.randrange(a, b)` as including `b`.
- Avoid Mistake: Picking an output option that starts at index `0` when the loop's minimum `start` is `1`.
- Avoid Mistake: Ignoring the `step` parameter in `randrange(start, stop, step)` and accepting values off the step grid.
- Examiner / Mentor Tip: Always write the minimum and maximum values of both variables explicitly when the question asks for `min`/`max`.
- Examiner / Mentor Tip: Check `end=` in `print()` carefully—CBSE PYQs often use `end='#'` or `end='@'` to format outputs on one line.
- Examiner / Mentor Tip: Remember `random.randrange(N)` with one argument starts at `0` and ends at `N - 1`.
7. Interactive Concept Check Quiz
Question: Given arr = [10, 20, 30, 40, 50], low = random.randint(1, 2), high = random.randint(2, 4), and for i in range(low, high): print(arr[i], end=' '), which output is IMPOSSIBLE?
8. Frequently Asked Questions
Can random.randrange(5, 5) work without an error?
What is the maximum possible value of int(random.random() * 5) + 1?
Why do CBSE 083 questions ask for 'probable outputs' instead of a single exact output?
Explore Related Lessons & Free Interactive Tools
- All 110 Guides in CBSE CS (083) & IP (065) Hub
- Python String Slicing s[::-1] and Negative Index Outputs
- Python String split() vs partition() and find() vs index()
- Python List Aliasing (a = b) vs Copy (b = a[:]) Exam Traps
- Interactive Tool: CBSE CS 083 Python Output Predictor Quiz
- Interactive Tool: CBSE SQL GROUP BY / HAVING / JOIN Query Evaluator
