How to generate Random Double number between 0.0 to 0.1 in Visual C#

In Visual Studio you can generate random Double number between 0.0 and 0.1, we are using the same Random, and Next Method with a little modification, if you haven’t see my How to Generate Random Integer number in Visual C#, be sure to go back and see that tutorial first before proceed on doing this tutorial.

Same as before, we are making the new Random Class,
Variables that contain next method
and print 3 random numbers
Let’s do it!
static void Main(string[] args)

        {

//Random Class
            Random rnd = new Random();
//Variable Declaration
            double a, b, c;
            a = rnd.NextDouble(); //NextDouble method
            b = rnd.NextDouble();
            c = rnd.NextDouble();
            Console.WriteLine(a);
            Console.WriteLine(b);
            Console.WriteLine(c);
        }

Here is the output

0.994341307782727
0.880812528953335
0.86230961692627
Press any key to continue . . .
And this is the second time I compile
0.317717866188715
0.83201662256942
0.415094685934062
Press any key to continue . . .

Cool, isn’t it? 🙂

Leave a Reply