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

Hello, nice to meet you

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Leave a Reply