+ 2

How can I get a simple random in in range in C# ? Thanks

10th Apr 2018, 7:14 AM
Epenschmiede
Epenschmiede - avatar
2 Answers
0
Random rnd = new Random(); int num = rnd.Next(1, 13);
10th Apr 2018, 9:15 AM
Bagshot
Bagshot - avatar
0
The Random class is used to create random numbers. (Pseudo-random that is of course.). Example: Random rnd = new Random(); int month = rnd.Next(1, 13); // creates a number between 1 and 12 int dice = rnd.Next(1, 7); // creates a number between 1 and 6 int card = rnd.Next(52); // creates a number between 0 and 51" Source: https://stackoverflow.com/questions/2706500/how-do-i-generate-a-random-int-number-in-c
10th Apr 2018, 9:15 AM
Emma