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.
(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]
(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:
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]
Everything you need to excel in your exams