How do I use random numbers in C#?
问题 I'm working on Pong in C# w/ XNA. I want to use a random number (within a range) to determine things such as whether or not the ball rebounds straight, or at an angle, and how fast the ball moves when it hits a paddle. I want to know how to implement it. 回答1: Use the Random class. For example: Random r = new Random(); int nextValue = r.Next(0, 100); // Returns a random number from 0-99 回答2: Unless you need cryptographically secure numbers, Random should be fine for you... but there are two