Produce a random number in a range using C#

RoR picture RoR · Oct 20, 2010 · Viewed 385.1k times · Source

How do I go about producing random numbers within a range?

Answer

Adriaan Stander picture Adriaan Stander · Oct 20, 2010

You can try

Random r = new Random();
int rInt = r.Next(0, 100); //for ints
int range = 100;
double rDouble = r.NextDouble()* range; //for doubles

Have a look at

Random Class, Random.Next Method (Int32, Int32) and Random.NextDouble Method