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

Button 2

Button 3

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.