Start by reading the instructions carefully, and writing a method which simulates rolling a die:
private static Random rand = new Random();
private static int RollDie()
{
return rand.Next(6) + 1;
}
And then test it:
for (int i = 0; i < 10; i++)
{
Console.WriteLine(RollDie());
}
Check that the output looks pretty random:
1
3
4
5
6
5
4
1
2
1
This is important, because if you look closely, you will spot an important difference between your code and mine: I create a static class level Random instance and reuse it eatc time I want a random number, while you create it when you want it inside the method and discard it at the end.
Random number sequences are initialised to a "different starting point" each time you create them - and this is normally the system clock for the computer they are running on. If you create two instance too close together, the clock time hasn't changed at all (just like the time in a boring lesson never changes between two looks at the clock) so the random sequence is started from the same point each time. If your computer is powerful enough - and it almost certainly is - then call a method with creates a Random instance and gets a single value from it 100 times in a small loop and it will generate 100 identical values! Move the instance into the method, and try again, and I get identical values very time:
3
3
3
3
3
3
3
3
3
3
My code creates an instance once, and reuses it, so it always gets random values - they may have some duplicates, but that's the nature of random numbers, they do that just like you can roll a real-world die three times and get a six each time - occasionally! :laugh:
So take little steps, and test them as you go: make sure that it does exactly what you expect it to before you move on to the next bit.
Now you have a working die thrower, you can start on the next bit: rolling three dies by calling the method three times, and checking what you get as a result.
This may help:
How to Write Code to Solve a Problem, A Beginner's Guide[
^]