How to generate a random integer in C#?
Hello everyone! I'm a beginner in C# and writing a simple guess-the-number game. I need the program to generate a random number from 1 to 100, and the user guesses it. But I ran into a problem: every time I run the program, the same number appears. Here's my code:
```csharp
Random random = new Random();
int secretNumber = random.Next(1, 101);
```
I create a new Random object, but each time I get 34, then 34, then 34 again... What am I doing wrong? I've heard you can use `Random.Next()` or `Random.NextDouble()`, but I need exactly an integer. Maybe I'm setting the range incorrectly? Please explain how to properly generate random integers in C#. I'd appreciate code examples and an explanation of why my code doesn't work. Thanks in advance!
<<>>