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 238 views
238 views asked Jul 31, 2018 by avibootz
1 answer 209 views
1 answer 201 views
1 answer 203 views
1 answer 183 views
1 answer 187 views
...