Get a Double Random Number | Quick Tip

This is useful since the Random() object can only export a double number between 0.0 and 1.0
class Program
{
    static void Main(string[] args)
    {
        double dr = GenRand(1.0, 20.0);
        Console.WriteLine(dr);
        Console.ReadLine();
    }

    static double GenRand(double one, double two)
    {
        Random rand = new Random();
        return one + rand.NextDouble() * (two - one);
    }
}
Resources: here
Advertisements