Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use random numbers in C#?

Tags:

c#

random

xna

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.

like image 876
Slateboard Avatar asked Jul 10 '10 03:07

Slateboard


1 Answers

Use the Random class. For example:

Random r = new Random();
int nextValue = r.Next(0, 100); // Returns a random number from 0-99
like image 192
Quartermeister Avatar answered Oct 28 '22 12:10

Quartermeister