随机复数

发布于 2024-09-17 05:32:22 字数 45 浏览 1 评论 0原文

我需要生成随机复数的算法,请帮助我知道如何生成随机数,但随机复数让我感到困惑

i need algorithm for generate random complex number please help i know how generate random number but random complex number confuse me

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时光病人 2024-09-24 05:32:22

我会简单地生成两个随机数,并使用一个作为实部,一个作为虚部。

I would simply generate two random numbers and use one for the real part and one for the imaginary part.

<逆流佳人身旁 2024-09-24 05:32:22
  1. 生成 2 个随机数 (x, y)(使用环境库中的内置 rand/rnd/random 类),其中 x 是实部,y code> 是虚部。

  2. 创建一个复数类(带有一个采用实部和虚部参数的构造函数)

  3. 使用来自的 2 个随机数步骤 1 创建一个复数,x + i y

  1. Generate 2 random numbers (x, y) (use the built-in rand/rnd/random class from your environment's libraries), where x is the real part and y is the imaginary part.

  2. Create a complex number class (with a constructor that takes a real and imaginary parameter)

  3. Use the 2 random numbers from step 1 to create a complex number, x + i y

够钟 2024-09-24 05:32:22

1.生成 2 个数字向量,其中一个是实向量,另一个是大小为 MAX_SIZE 的虚向量,使用不同的种子随机生成。

2.使用任何分布随机洗牌向量(实向量+虚向量)中的数字让我们说使用std::random_shuffle(均匀分布)。

3.随机生成一个索引,并对 MAX_SIZE 应用模运算符,并从第一个数组中选择索引,该索引将提供您的随机数的实部。

4.使用步骤 3 获取随机数的虚部。

5.使用步骤 3 和步骤 4 中获得的数字创建一个复数,并将其存储在容器中。

6.转到步骤3并检查是否需要更复杂的数字;如果没有则中断;

1.Generate 2 vector of numbers say one is real_vector and another is imaginary_vector of size say MAX_SIZE to be generated randomly with differrent seeds.

2.Random shuffle the numbers in vectors(real_vector+imaginary_vector) using any distribution let us say use of std::random_shuffle(uniform distribution).

3.randomly generate a index and apply modulo operator for MAX_SIZE and select index from first array that will provide an real part of ur random number.

4.use step 3 to get imaginary part of your random number.

5.Create a complex number using number got from step 3 and step 4 and store in a container.

6.go to step 3 and check if you want any more complex number;if no then break;

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文