c++ - 生成随机数对以形成二维随机点

标签 c++ c translation

<分区>

我试图理解一个愚蠢的句子:

"这个函数会进行一次实验,会生成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);

希望对您有所帮助!

关于c++ - 生成随机数对以形成二维随机点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20533257/

相关文章:

c++ - 着色器输入布局无效

c - 如何解决错误 : expected identifier or '('

Symfony2 twig 翻译 {% trans %} 标签中的变量值

c++ - 如何打印混合 ascii 字符和 unicode 的字符串的每个字符?

c++ - 有效地返回未修改的参数

条件表达式。大写转小写

c - 如何创建具有不同名称的子进程

architecture - React/Redux 和多语言(国际化)应用程序 - 架构

internationalization - 众包翻译

c++ - 为 64 位 Windows 构建 ZBar