Quick Notes on getting random (pseudo random) numbers in C#

Create an instance of a random number generator: –

Random rnd = new Random();

Grab random numbers from it as required using: –

int i = rnd.Next(1, 100);

double d = rnd.NextDouble();

The latter will give a value between 0.0 and 1.0

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: