How to use static class-level Random in C#

2 Answers

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main()
        {
            Rnd();
            Rnd();
            Rnd();
        }
        static Random _r = new Random();
        static void Rnd()
        {
            int num = _r.Next();

            Console.WriteLine(num);
        }
    }
}


/*
run:
   
671830693
1700910643
571562320
 
*/

 



answered Aug 25, 2018 by avibootz
0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main()
        {
            Rnd();
            Rnd();
            Rnd();
        }
        static Random _r = new Random();
        static void Rnd()
        {
            int num = _r.Next(10);

            Console.WriteLine(num);
        }
    }
}


/*
run:
   
8
3
6
 
*/

 



answered Aug 25, 2018 by avibootz

Related questions

2 answers 236 views
236 views asked Jul 31, 2018 by avibootz
1 answer 206 views
1 answer 200 views
1 answer 200 views
1 answer 180 views
1 answer 184 views
...