ITPEC FE Morning April 2023 Question 4
Random(n) is a function that returns an integer of 0 or more and less than n with a uniform probability. When the series of procedures below is run on the integer type variables A, B, and C, what is the probability that the value of C will be 0?
A = Random(10)
B = Random(10)
C = A−B
Explanation
1/10 — C is 0 exactly when A = B.
Random(10) returns one of the ten integers 0 to 9, each with probability 1/10, and the two calls are independent.
- •Equally likely pairs (A, B): 10 × 10 = 100
- •Pairs with A = B: (0, 0), (1, 1), …, (9, 9), that is 10
- •Probability: 10 ÷ 100 = 1 ÷ 10
Equivalently, whatever A turns out to be, B matches it with probability 1/10.
Answer (c)
Why not others:
- •(a) 1/100 — the probability of one particular pair, such as A = B = 0, not of all ten matching pairs
- •(b) 1/20 — close to treating the 19 possible differences from −9 to 9 as equally likely; they are not, and 0 is the most likely difference
- •(d) 1/5 — would need 20 matching pairs out of 100, but only 10 exist
Key rule: Two independent uniform picks from n values are equal with probability 1 ÷ n: fix the first, and the second must match it.
Basic Theory · AI-written, may contain errors
This question comes from an official ITPEC past paper. ITPEC Practice is an independent study tool and is not affiliated with ITPEC. See the official FE past-paper collection or Report an issue.