我试图理解一个愚蠢的句子:
"这个函数会进行一次实验,会生成npoints个随机有理数对(x, y),到
形成 npoints 个随机二维点。这些点的x、y坐标应该保持在区间内
[-r, r]”
因此,在这个函数中,npoints 是整数,值为 1000,可以是不同的值。函数获取数 a 和 b 以及度数 thera1 和 theta2,以及 r,即 r(θ) = ae^bθ
。那么,谁能向我解释一下,这个函数实际上必须做什么?
附言。它实际上不是错误,问题是我无法理解它可能是因为我的英语不太好,对此感到抱歉,但它不适用于英语网站,因为它的代码:)
我的解读如下:
"This function will perform a single experiment. It will generate
npoints random rational number pairs (x, y),
您需要生成随机的 x/y 坐标对。 “有理数”只是意味着数字可以写成两个整数的商(所以 e 和 PI 不存在)。
to form npoints random 2 dimensional points.
你应该总共得到“npoints”。
The x, and y coordinates of these points should remain in the interval [-r, r]"
因此,您需要将点都保持在 0 的“r”距离内。换句话说,没有点的 x 或 y 坐标小于 -r 或大于 r。在函数形式中,这看起来像:
/* The point structure */
struct POINT {
int x;
int y;
};
/* npoints -- The number of points to generate */
/* range -- The maximum (positive/negative) value for the points */
POINT *GetRandomCoordinates(int npoints, int range);
希望对您有所帮助!