Random Number Generator in C# Using System.Random

  • Thread starter Thread starter TheDemx27
  • Start date Start date
  • Tags Tags
    Generator Random
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 2K views
TheDemx27
Gold Member
Messages
169
Reaction score
13
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        public class RandomNextDemo
        {
            static void NoBoundsRandoms(int seed)
            {
                Console.WriteLine(
                    "\nRandom object, seed = {0}, no bounds:", seed);
                Random randObj = new Random (seed);
            }
        }
        
        static void Main(string[] args)
        {
            RandomNextDemo.NoBoundsRandoms();

        }  
    }
}

Error1'ConsoleApplication1.Program.RandomNextDemo.NoBoundsRandoms(int)' is inaccessible due to its protection

In C#, of course.
 
Physics news on Phys.org
Change the access modifier: static public void NoBoundsRandoms(int seed) by default it would set the access modifier to private which is what your current code does.
 
Last edited:
MathWarrior said:
Change the access modifier: static public void NoBoundsRandoms(int seed) by default it would set the access modifier to private which is what your current code does.

Thanks, I guess I also forgot to give the method the value "seed" it called for.