Past-paper question · 2019 May-June · Paper 21 · Q5(b)

Question 5(b) 2019 · May-June · Paper 21 · 8 marks

Original past-paper question for 5(B)
Original past-paper question for 5(B)
Original past-paper question for 5(B)
Original past-paper question for 5(B)
Reveal official mark-scheme answer Official mark-scheme answer for 5(B)

Official answer for Question 5

Part (b)

✓
PROCEDURE TestRand()

Question 8

✓
DECLARE
✓
MyArray : ARRAY [1:50] OF BOOLEAN
✓
DECLARE
✓
Attempts : INTEGER
✓
DECLARE
✓
NumFound : INTEGER
✓
DECLARE
✓
ThisRndNumber : INTEGER
✓
DECLARE
✓
Index : INTEGER
✓
FOR Index ← 1 TO 50
✓
Myarray[Index] ← FALSE
✓
ENDFOR
✓
NumFound ← 0
✓
Attempts ← 0
✓
WHILE NumFound < 50
✓
ThisRndNumber ← 1 + INT(RAND(50))
✓
Attempts ← Attempts + 1
✓
IF MyArray[ThisRndNumber] = FALSE
✓
THEN
✓
MyArray[ThisRndNumber] ← TRUE
✓
NumFound ← NumFound + 1
✓
ENDIF
✓
ENDWHILE
✓
OUTPUT "Number of calls to RAND() was ", Attempts
✓
ENDPROCEDURE
✓
1 mark for each of the following:

Question 1

✓
Declaration of array of 50 elements

Question 2

✓
Loop to initialise array

Question 3

✓
Conditional loop stopping when all numbers generated

Question 4

✓
Generate a random integer in the range 1 to 50 in a loop

Question 5

✓
Count each call to RND() in a loop

Question 6

✓
check if the number has already been generated in a loop

Question 7

✓
if true, record as generated in a loop

Question 8

✓
Output a message plus the Attempts outside a loop
✓
9608/21
✓
Cambridge International AS/A Level – Mark Scheme
✓
May/June 2019
✓
PUBLISHED
✓
Question
✓
Answer
✓
Marks

Mark scheme 9608_s19_ms_21.pdf →

Show text version of question

Question 5

Part (b)

Part (b)

A student is learning about random number generation.

She is investigating how many times the random function needs to be called before every number in a given series is generated.

She is using pseudocode to develop a procedure, TestRand(), which will:

  • use the random number function to generate an integer value in the range 1 to 50
  • inclusive

  • count how many times the random function needs to be called before all 50 values have
  • been generated

  • output a message giving the number of times the random function was called.

Question 13

Write pseudocode for the procedure TestRand().

For the built-in functions list, refer to the Appendix on page 16.

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

...................................................................................................................................................

.............................................................................................................................................

[8]

Question 14

Topic relevance

Why this question appears here

71% assigned-topic match · Programming › Structured programming

Topic-match percentages estimate how closely each question fits the selected syllabus topic. They are a guide for choosing stricter or broader practice.

Permanent source page: Educate A Change · From 9608_s19_qp_21.pdf

Keep practising this topic