dimanche 6 octobre 2019

Random point 2D with limits

I need to generate a 1000 random numbers as [x,y] coordinates. The highest x value is 76, while for y it is 15. I have also made a Point 2D class which should read the X and Y coorinates and do some math equations (the class is called Punkt2D, and it uses X and Y like distance.X and distance.Y to calculate).

For now I only get 1000 random numbers between 0 to 75. How do I turn it into coordinate values?

(kolonner means columns, rader mens rows and nummer mens number).

public const int MaxX = 76;
        public const int MaxY = 15;
        public const int min = 0;
        public const int rader = 1000;
        public const int kolonner = 2;

        public static void Main(string[] args)
        {
            Random r = new Random();
            int[,] nummer = new int[kolonner,rader];
            for (int m = 0; m < kolonner; m++)
            {
                for (int n = 0; n < 1000; n++)
                {
                    nummer[m,n] = r.Next(0,MaxX);
                    Console.WriteLine(Convert.ToString(nummer[m, n]));
                }
            }
        }

I did also start on this method here, where I removed the loops.

int row = r.Next(nummer.GetLength(0));
            int column = r.Next(nummer.GetLength(1));
            int randomNummer = nummer[row, column];
            Console.WriteLine(Convert.ToString(nummer));

Thanks in advance.




Aucun commentaire:

Enregistrer un commentaire