Rolling a 6, 8, 10 and 12 sided dice.
Select the button below to open the C# program in a new window. Run the program and read the lines of code to see if you can understand how it works. It will be helpful to arrange your display so that you can have this browser window on one side of the screen and the code on the other.
Watch this video to learn about the new concepts shown in the program:
The new commands used in this program and others that may be useful. Select them below to learn more:
Initialises a new instance of the Random class. This allows you to generate random numbers.
If you specify the parameter y, this sets the seed to x to be used by the random number algorithm. The value of y can be omitted to use the current time as the seed number instead. Using the time of day as the seed gives the impression of truly random numbers.
Generates a random number between y (inclusive) and z (exclusive).
Questions to think about with this program to check your understanding:
Identify two constants in the program that could be variables instead.
The numbers 1 and 7 could be constants in this version of the program although that would limit the program to only simulating the roll of a six-sided dice.
State what the two parameters are used for in the randint command in line 18.
The lowest and one above the highest number that can be generated by the random number algorithm.
Change the program so that it:
Roll a D6
You rolled a 3
Roll a D8
You rolled an 8
Roll a D10
You rolled a 4
Roll a D12
You rolled an 11
Use the flowcharts if you need more support in understanding the steps required to meet the criteria. Use the Parsons code sorting exercise only if you are really stuck.
Run your code several times to check that your program has met the success criteria.