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

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s