Search code examples
c#.netrandom

Produce a random number in a range using C#


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


Solution

  • You can try

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

    Have a look at

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