Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,959 questions

51,901 answers

573 users

How to generate random number of type double in C#

4 Answers

0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                double d;

                Random generator = new Random();
                d = generator.NextDouble();
                Console.WriteLine(d); // 0.947165774622544
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}

/*
run:
  
0.947165774622544
 
*/


answered Mar 27, 2015 by avibootz
edited Mar 27, 2015 by avibootz
0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                double d;

                Random generator = new Random();
                d = generator.NextDouble();
                Console.WriteLine("{0:F8}", d); // 0.92800123
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}

/*
run:
  
0.92800123
 
*/


answered Mar 27, 2015 by avibootz
0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                double d;

                Random generator = new Random();
                for (int i = 0; i < 5; i++)
                {
                    d = generator.NextDouble();
                    Console.WriteLine("{0:F8}", d); 
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}

/*
run:
  
0.38425761
0.96099728
0.02579850
0.58213095
0.75735805
 
*/


answered Mar 27, 2015 by avibootz
0 votes
using System;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                double d;

                Random generator = new Random();
                for (int i = 0; i < 5; i++)
                {
                    d = generator.NextDouble() * 100;
                    Console.WriteLine("{0:F8}", d); 
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    }
}

/*
run:
  
30.29377345
0.82755862
16.86265283
94.93592600
76.88212133
 
*/


answered Mar 27, 2015 by avibootz

Related questions

1 answer 105 views
1 answer 130 views
1 answer 149 views
149 views asked Jan 12, 2017 by avibootz
1 answer 127 views
127 views asked Jan 12, 2017 by avibootz
1 answer 135 views
1 answer 96 views
...