The random and statistics Modules Class 11: Possible Outputs and Central Values
Updated 17 October 2026 · Fact-checked
random.randint(a, b) returns an integer from a to b inclusive; random.randrange(start, stop, step) follows the range() rules and excludes stop; random.random() returns a float from 0 up to but not including 1. statistics.mean, median and mode give the average, the middle value and the most frequent value of a list. In possible-output questions, find the minimum and maximum values and list what is attainable.
Understand The random and statistics Modules: Possible Output Questions
random module.
random.random(): float x with 0 <= x < 1.random.randint(a, b): integer from a to b, both included.random.randrange(start, stop, step): like range(): stop is excluded. randrange(1, 6) gives 1 to 5; randrange(10, 50, 10) gives 10, 20, 30 or 40.
Possible output questions. Work out the smallest and largest value of each random call, combine them, and decide which printed values can or cannot occur.
import random
a = random.randint(1, 3)
b = random.randint(2, 4)
print(a + b)a can be 1, 2 or 3 and b can be 2, 3 or 4. The sum can be any of 3, 4, 5, 6, 7. So 2 and 8 cannot be printed, while 4 and 7 can.
statistics module. import statistics.
statistics.mean(data): arithmetic mean. mean([2, 3, 4, 5]) = 14 / 4 = 3.5; mean([1, 2, 3, 4, 4]) = 14 / 5 = 2.8.statistics.median(data): middle value of sorted data; for an even number of items, the average of the two middle values. median([5, 1, 3]) = 3; median([1, 3, 5, 7]) = 4.0.statistics.mode(data): most frequent value. mode([1, 1, 2, 3, 3, 3, 4]) = 3.
Remember. The data must be a list or tuple of numbers. median sorts the data internally, so the order does not matter.
Program: two dice.
import random
d1 = random.randint(1, 6)
d2 = random.randint(1, 6)
print(d1 + d2)Each die is an integer 1 to 6, so the sum is between 2 and 12.
The random and statistics Modules: Possible Output Questions: key facts
- random functions
random() 0 up to but below 1 randint(a, b) a to b inclusive randrange(start, stop, step) stop excluded - Know the end points.
- Possible outputs
- Find min and max of each call
- Combine the extreme values
- List attainable results
- Cannot-print questions.
- statistics
mean sum divided by count median middle value of sorted data mode most frequent value - import statistics.
- Median rule
- Odd count: the middle item | Even count: average of the two middle items
- Sort first.
How to answer The random and statistics Modules: Possible Output Questions questions
Never guess the random output; reason about the possible range.
- 1Write the range of every random call, noting whether the end point is included.
- 2Combine ranges for the printed expression.
- 3List what can and cannot be printed.
- 4For statistics, sort the data, then count (mode), pick the middle (median) or add and divide (mean).
- 5State any value you are not sure about as a range, not as a single number.
The random and statistics Modules: Possible Output Questions in real life
The idea, met in an everyday situation. Answer the question in your own words, then compare with the model answer. The one-line hook is what to remember.
A game of two dice
Suppose a board game adds two dice thrown with random.randint(1, 6).
Between which values does the sum lie?
Try it first, then show the solutionSolution
- Smallest is 1 + 1 = 2.
- Largest is 6 + 6 = 12.
Answer: The sum is from 2 to 12.
Memory hook: Minimum plus minimum to maximum plus maximum.
Tricks to remember The random and statistics Modules: Possible Output Questions
Short memory aids. Say each one aloud once, then use it on a question the same day.
randint includes both ends
randint(1, 6) can give 1 and 6.
Use it when: randint.
randrange follows range
The stop value is excluded.
Use it when: randrange.
The random and statistics Modules: Possible Output Questions: solved examples
Ordered from board level to HOTS. Try each one before you open the solution.
Example 1: randint range · 1 mark · MCQBoard level
Which of the following values can random.randint(2, 5) NOT return?
(a) 2
(b) 3
(c) 5
(d) 6
Try it first, then show the solutionSolution
- Both end points are included, so the range is 2 to 5.
Answer: (d) 6
Example 2: Possible values · 2 marks · Short answerBoard level
List all values that random.randrange(10, 50, 10) can return and say whether 50 is possible. (2 marks)
Try it first, then show the solutionSolution
- randrange works like range(10, 50, 10): 10, 20, 30, 40.
- 50 is the stop value and is excluded.
Answer: 10, 20, 30, 40; 50 is not possible.
Example 3: Possible sums · 4 marks · Short answerHarder board level
Study the code and list which of the values 2, 4, 7, 8 can be printed:
import random
a = random.randint(1, 3)
b = random.randint(2, 4)
print(a + b)(4 marks)
Try it first, then show the solutionSolution
- Smallest value: 1 + 2 = 3. Largest value: 3 + 4 = 7.
- Every integer between 3 and 7 can occur.
- So 4 and 7 can be printed; 2 and 8 cannot.
Answer: 4 and 7 are possible; 2 and 8 are not.
Example 4: Central values · 4 marks · Short answerHarder board level
Find the mean, median and mode: (i) mean([2, 3, 4, 5]); (ii) median([1, 3, 5, 7]); (iii) mode([1, 1, 2, 3, 3, 3, 4]); (iv) median([9, 2, 5]). (4 marks)
Try it first, then show the solutionSolution
- (i) (2 + 3 + 4 + 5) / 4 = 3.5.
- (ii) Even count: (3 + 5) / 2 = 4.0.
- (iii) 3 occurs three times, more than any other value, so the mode is 3.
- (iv) Sorted [2, 5, 9]: the middle value is 5.
Answer: (i) 3.5 (ii) 4.0 (iii) 3 (iv) 5
Example 5: Lottery logic · 5 marks · Short answerHOTS / competency
A program picks a lucky number with n = random.randrange(1, 10, 3) and prints n * 2. Find all possible outputs and explain why 20 can never be printed. (5 marks)
Try it first, then show the solutionSolution
- randrange(1, 10, 3) works like range(1, 10, 3): 1, 4, 7.
- Outputs: 2, 8, 14.
- 20 would need n = 10, but 10 is the stop value, which is excluded; the largest value possible is 7.
- So only 2, 8 and 14 can be printed.
Answer: Possible outputs: 2, 8, 14; 20 is impossible.
Where students lose marks in The random and statistics Modules: Possible Output Questions
The slips examiners see most often, and what to write instead.
Mistake: Excluding the end of randint
Treating it like range.
Wrong working
randint(1, 6) gives 1 to 5.
Right working
randint(1, 6) gives 1 to 6.
Do this: randint includes both ends.
Usually costs: 1 mark
Mistake: Including the stop of randrange
Same slip the other way.
Wrong working
randrange(1, 6) can give 6.
Right working
randrange(1, 6) gives 1 to 5.
Do this: Stop is excluded.
Usually costs: 1 mark
Mistake: Taking the middle without sorting
Median of unsorted data.
Wrong working
median([9, 2, 5]) = 2
Right working
Sort first: median = 5.
Do this: Sort before choosing the middle.
Usually costs: 1 mark
Exam tips
- Write the minimum and maximum of every random call.
- List the possible outputs in order.
- Show the sorted list in median answers.
- State the import line in every program.
Practice questions on The random and statistics Modules: Possible Output Questions
Write each answer on paper first. Open the hint only if you are stuck, and the answer only when you have finished.
Q1 · 1 mark · MCQBoard level
random.random() returns a value x such that:
(a) 0 < x <= 1
(b) 0 <= x < 1
(c) 1 <= x <= 10
(d) x is an integerHint
Includes 0, excludes 1.
Answer
(b) 0 <= x < 1
Q2 · 3 marks · Short answerHarder board level
What are the minimum and maximum values printed?
import random x = random.randint(1, 4) y = random.randrange(2, 5) print(x * y)(3 marks)
Hint
y is 2, 3 or 4.
Answer
x is 1 to 4 and y is 2 to 4. The minimum is 1 x 2 = 2 and the maximum is 4 x 4 = 16.
Q3 · 3 marks · Short answerHarder board level
Find the mean, median and mode of the list [4, 7, 7, 2, 10]. (3 marks)
Hint
Sort: 2, 4, 7, 7, 10.
Answer
Mean = 30 / 5 = 6. Median = 7 (middle of 2, 4, 7, 7, 10). Mode = 7.
Q4 · 1 mark · Assertion-reasonHarder board level
Assertion (A): random.randint(5, 10) can return 10.
Reason (R): Both end points are included in randint.
(a) Both A and R are true, and R is the correct explanation of A.
(b) Both A and R are true, but R is not the correct explanation of A.
(c) A is true, but R is false.
(d) A is false, but R is true.Hint
randint includes both ends.
Answer
(a) Both A and R are true, and R is the correct explanation of A.
Q5 · 4 marks · Short answerHOTS / competency
A program rolls two dice and prints the sum. The student claims 1 and 13 are possible outputs. Write the program, find the range of sums and show who is right. (4 marks)
Hint
Minimum 2, maximum 12.
Answer
import random; a = random.randint(1, 6); b = random.randint(1, 6); print(a + b). The smallest sum is 1 + 1 = 2 and the largest is 6 + 6 = 12. Neither 1 nor 13 can be printed, so the student is wrong.
Test your recall
Answer in your head or on paper first, then open the card. Pulling an answer out of memory makes it stick far better than re-reading.
1.Does randint include the end value?Show answer
Yes.
2.Does randrange include the stop value?Show answer
No.
3.Range of random()?Show answer
0 up to but not including 1.
4.Median of an even-sized list?Show answer
Average of the two middle values.
5.Which module has mean and mode?Show answer
statistics.
The random and statistics Modules: Possible Output Questions: frequently asked questions
Can random programs be tested exactly?
Not by fixed output; you reason about the possible range.
What is mode?
The value that occurs most often.
Do I need to sort for median()?
No, the function sorts internally, but you should sort when doing it by hand.