Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 带极限的二维随机点_C#_Loops_Vector_Random_Coordinates - Fatal编程技术网

C# 带极限的二维随机点

C# 带极限的二维随机点,c#,loops,vector,random,coordinates,C#,Loops,Vector,Random,Coordinates,我需要生成1000个随机数作为[x,y]坐标。最高x值为76,而y值为15。我还制作了一个Point2D类,该类应该阅读X和Y坐标,并做一些数学方程(该类称为Punkt2D,它使用X和Y,如distance.X和distance.Y来计算) 现在我只得到1000个介于0到75之间的随机数。如何将其转换为坐标值 (kolonner表示列、rader mens行和nummer mens编号) 提前感谢。我看到了两种生成随机点的方法。让我们假设范围为x={0..M-1}和y={0..N-1} 创建两个

我需要生成1000个随机数作为[x,y]坐标。最高x值为76,而y值为15。我还制作了一个Point2D类,该类应该阅读X和Y坐标,并做一些数学方程(该类称为Punkt2D,它使用X和Y,如distance.X和distance.Y来计算)

现在我只得到1000个介于0到75之间的随机数。如何将其转换为坐标值

(kolonner表示列、rader mens行和nummer mens编号)


提前感谢。

我看到了两种生成随机点的方法。让我们假设范围为
x={0..M-1}
y={0..N-1}

  • 创建两个独立的随机数
    intx=random.Next(M);int y=random.Next(N)
    。下限为
    0
    。请注意,上限是独占的。因此,
    M
    N
    必须比最大值高1。它们表示沿一个轴的可能值的数量(图像中的像素数量)

  • 生成一个随机值
    int r=random.Next(M*N)然后获得
    int x=r%M的坐标;int y=r/M
    %
    是产生除法剩余部分的模运算符)

  • 您可以通过以下方式获得分数:

    var p = new Point(x, y);
    

    “将其转换为坐标值”是什么意思?您的坐标值是否有小数点,或者您只是希望它能够选择负数?int[,]是错误的数据类型,您需要一个元组并使用新的数据类型生成它。
    List
    也可以。
    int row = r.Next(nummer.GetLength(0));
                int column = r.Next(nummer.GetLength(1));
                int randomNummer = nummer[row, column];
                Console.WriteLine(Convert.ToString(nummer));
    
    const int M = 77, Y = 16; // Gives range of { 0..76, 0..15 }.
    
    var p = new Point(x, y);