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 351 views
351 views asked Jul 31, 2018 by avibootz
1 answer 307 views
1 answer 293 views
1 answer 292 views
1 answer 272 views
1 answer 287 views
...