NSWI170 Computer Systems
Lab test example
The following specification is a demonstration of an assignment that could be encountered in the final lab test.
The objective is to create a random number generator that will simulate dice throws in the Advanced Dungeons and Dragons game. The game uses various types of polyhedral dice with different numbers of sides (d4, d6, d8, ...). Furthermore, a generated random number represents a sum of multiple throws. For instance, 3d6 means that the player should throw 3 times using a dice with 6 sides (cube) and take the sum of these three throws (which is a number between 3 and 18).
The dice application is controlled by 3 buttons and displays the results on the 4-digit LED display. It operates in two modes. In normal mode, it displays the last generated number on the LED display. In configuration mode, it displays the type (and repetition factor) of dice being simulated. The first digit (1-9) displays the number of throws, the second digit displays the symbol 'd', and the remaining two digits indicate the type of dice (d4, d6, d8, d10, d12, d20, and d100 should be supported;
d100 is displayed as '00' on the display).
Button 1
- switches the dice to normal mode
- whilst pressed down, the random data are gathered (result is being generated)
- when the button is released, a new random result has to be displayed
Button 2
- switches the dice to configuration mode
- increments the number of throws (if 9 is exceeded, the number returns to 1)
Button 3
- switches the dice to configuration mode
- changes the dice type (dices
d4-d100from the list above are cycled)
It might be a good idea to show some 'activity' on the display whilst the random number is being generated (when button 1 is pressed). You may show currently computed random numbers (if they change fast enough so the user cannot possibly stop at the right number), or you may create some sort of animation on the LED display or by means of the other onboard LEDs.
Remember that the probability distribution is not uniform (for more than one die). Your simulator must use a counter or a time measurement of how long button 1 has been pressed to get a random number (which follows uniform distribution). You may use additional pseudo-random generators (Arduino built-in functions are adequate) to assist you with this task, but the initial randomness has to be tied somehow to the button event duration.
The simplest correct solution is to generate the result as a sum of multiple random numbers with uniform distribution (for instance 3d6 is a sum of three random values from 1-6 range). The relation between randomness and the duration of the 1st button press can be easily achieved by generating random throws as long as the button is pressed in rapid succession. If you are displaying the results of throws continuously, it will also take care of the issue of showing some activity on the display whilst the numbers are being generated.
Some applications and games for practice
You can always check your lab slides, write your lecturer for more ideas, or ask AI to generate some more exercises for you. Here are some examples of exercises and fun games that you can try to implement as a preparation for the test:
Reaction Time Meter
Random delay → LED turns on → user presses button → time displayed.
Countdown Timer
Buttons set time; countdown runs; buzzer beeps at zero.
Binary Guess Game
Number generated; user cycles guess with buttons; display shows result / hints.
Simple Lock (PIN Code)
User enters 4-digit code with buttons; correct code triggers buzzer/LED.
LED Animation Player
Buttons set number of glyphs; Show a random pattern with a given number of glyphs; button press changes pattern.
Metronome
Adjustable tempo via buttons; LED + buzzer tick; display shows BPM.
Speed Click Game for Two Players
Two buttons; count presses in 5 seconds; display shows winner or tie.
Sequence Memory (Simon-lite)
LEDs flash sequence; user repeats with buttons; sequence grows.
3-Button Piano
Two buttons select octave and note; third button plays the note; display shows current selection.
Tennis scoreboard
Two buttons = two players; display alternates scores or shows difference.