To create a random number in C# use the
If you need more than one random number keep the
Random instance and reuse it.
Creating new instances too close to each other will produce the same series of random numbers
as the random generator is seeded from the system clock.
Here is an example where the same instance is reused:
var random = new Random(); int month = random.Next(1, 13); // creates a number between 1 and 12 int dice = random.Next(1, 7); // creates a number between 1 and 6 int card = random.Next(52); // creates a number between 0 and 51