Random Number Generator in C# Using System.Random

  • Thread starter Thread starter TheDemx27
  • Start date Start date
  • Tags Tags
    Generator Random
AI Thread Summary
The discussion centers on a C# code snippet that demonstrates the use of a Random object. The primary issue raised is an accessibility error when trying to call the method NoBoundsRandoms from the Main method. The error occurs because the method is private by default, making it inaccessible. To resolve this, the access modifier for NoBoundsRandoms should be changed to public. Additionally, it is noted that the method call in Main is missing the required parameter "seed," which needs to be provided for the method to function correctly. The conversation emphasizes the importance of correctly setting access modifiers and ensuring all required parameters are included in method calls.
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.
 
Technology 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.
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top