Fig. 1 shows a simplified online card-game program. Four players are dealt a starting card from a virtual deck numbered 0 to 51. The game must not deal the ...

Assessment: Computer Science 9210 | Paper 1 Mock 01 | Programming (on-screen) Subject: Computer Science - 9210

Question 1 Report

Fig. 1 shows a simplified online card-game program. Four players are dealt a starting card from a virtual deck numbered 0 to 51. The game must not deal the same card to two players. The existing code creates a random pointer, checks whether that pointer has already been used, and repeats the selection when necessary. A message is displayed after each successful deal. The programmer is considering a second design: make a list containing all 52 pointers, shuffle the list once, then deal the first four pointers. Both designs can be used in the main program.

card ← RANDOM(0,51)card used?noyes, choose againmark used and deal cardAlternative: shuffle pointers 0 to 51, then use each pointer once.© EAGLE BEACON GLOBAL

(a) Explain why RANDOM(0,51) is an appropriate initial range for a card pointer. [2]
(b) When the random pointer has already been used, explain how the loop in Fig. 1 prevents a duplicate deal. [2]
(c) Explain two advantages of shuffling a list of pointers before dealing cards. [4]
(d) When testing either design, explain two test cases that would help confirm the boundary card pointers are dealt correctly. [2]
(e) Explain why a pseudorandom-number generator may be acceptable for this game but not for a security-critical card system involving real money. [2]

Answer Details

(a) The valid card pointers start at 0 and end at 51. Therefore RANDOM(0,51) can select every one of the 52 card pointers. [2]

(b) The program checks whether the generated pointer has already been marked as used. If it has, the loop generates another pointer and repeats this process until it obtains an unused pointer. This prevents the same card being dealt twice. [2]

(c) Shuffling a list of pointers has these advantages:

  • Every pointer occurs only once in the shuffled list, so duplicate deals cannot occur.
  • No repeated random-generation and used-card checking loop is required.
  • Dealing can be quicker or have more predictable processing time.
  • All cards remain available in a random order.

Any two well-explained advantages earn credit. [4]

(d) Test that pointer 0 is accepted and dealt, and test that pointer 51 is accepted and dealt. These are the lower and upper boundary pointers. [2]

(e) A pseudorandom generator is acceptable for a game where fair-looking, unpredictable play is sufficient. A real-money security-critical system needs stronger unpredictability because an attacker might predict or exploit pseudorandom output. [2]

Download The App On Google Playstore

Everything you need to excel in your exams

Green Bridge CBT Mobile App
Personalized AI Learning Chat Assistant
200,000+ Exam Questions Across IGCSE, JAMB, WAEC & NECO
Over 3,900 Lesson Notes
Offline Support - Learn Anytime, Anywhere
Green Bridge Timetable
Literature Summaries & Potential Questions
Track Your Performance & Progress
In-depth Explanations for Comprehensive Learning