Worked solution from the Programming Paper 2 Problem-solving and Programming booklet, Part 2 of 3.
Keep a base value. Each time, add a random amount from 0 up to just below the step size, so the new number is always bigger than the old one. Then raise the base by the step:
PROCEDURE RandList()
DECLARE Count, BaseNum, ThisNum : INTEGER
CONSTANT StepVal = 10
BaseNum ← 0
FOR Count ← 1 TO 25
ThisNum ← BaseNum + INT(RAND(StepVal))
OUTPUT ThisNum
BaseNum ← BaseNum + StepVal
NEXT Count
ENDPROCEDUREProcedure heading and ending [1]
Loop counter Count declared as a local INTEGER [1]
Loop that runs 25 times (one number each time) [1]
Random number made with INT and RAND inside the loop [1]
Number made greater than the previous one, and the 'previous' value updated (here BaseNum increases by StepVal) [1]
Random number output inside the loop [1]
The condition says: the next value is equal to or smaller than the current value. Write the same test as one comparison:
IF Result[x + 1] <= Result[x] THEN [1]
Result[x] >= Result[x + 1] also scores.
▶ Starts at Q4 (55:26)
Starts at Q4 (55:26) · by Zafar Ali Khan (ZAK). Tap the picture to open it on YouTube.
Solutions follow the official Cambridge mark schemes; marks are shown in grey. Videos are from other YouTube channels. Paper codes read component / series / year: M/J = May/June, O/N = October/November. Past-paper questions © UCLES, reproduced for classroom practice.