生成不同的正态分布的随机数序列
Generation of different sequence of random numbers that are normally distributed in c++
我试图生成正态分布的随机数。我在c++11中使用了随机头,我得到了随机数,但无论何时执行程序,都保持相同的序列。问题是我如何在执行程序时获得不同的序列?这是我的代码:
srand(time(NULL));
complex<double> finding[10];
complex<double> com_one(rand(), rand());
complex<double> com_two(rand(), rand());
mt19937 mt(1729);
normal_distribution<float>dist(0,1);
for(int i = 0; i<16; ++i){
cout << dist(mt)<<", ";
}
cout<<"nn"<<endl;
for(int i=0;i<10;i++){
complex<double> com_three(rand(), rand());
finding[i]= com_three;
}
for (int i =0; i<10;i++){
cout <<"no "<<i<<" element of the finding array is: ";
cout <<finding[i]<< endl;
}
cout << "The first complex number is" << endl;
cout << com_one.real() << "+" << com_one.imag()
<< "i" << endl;
你会得到相同的序列,因为你在这里用相同的种子初始化引擎:
mt19937 mt(1729); // 1729 is the seed
当你想要一个不同的序列时,你需要找到一种方法来设置不同的种子。如何做到这一点取决于代码的预期行为。您可以从命令行、配置文件中读取它,或者如果您不关心再现性(参见例如std::random_device
),则可以从非确定性随机设备中生成它。
相关文章:
- 改变或缩放两个正态分布以具有特定的相关系数
- 从 C++ 函数与 Python 函数返回的不一致值用于偏斜正态分布
- 逆生存函数与正态分布的PPF(ICDF)?
- C 中高斯的随机正态分布
- C :实用程序名称空间中的正态分布
- MT19937和正态分布
- 在 Xcode 8.3 上构建一个C++正态分布式随机数生成器
- 生成C++中的正态分布随机数
- 如何从限于一定间隔的正态分布进行采样,即C 实现
- 带参数的累积正态分布函数的逆
- 在.h文件中声明正态分布生成器
- Box Muller Transform在实现正态分布PRNG时的问题
- 接受拒绝算法 C++ 正态分布
- 在C 中实现正态分布的统一比率
- 如何创建一个在单独的方法中工作的c++随机正态分布
- 如何在C++中随机采样具有给定平均值和标准误差的正态分布
- C++生成范围内服从正态分布的随机数
- 随机数的正态分布会挂起程序
- 生成不同的正态分布的随机数序列
- 为什么 boost 的随机数生成(在正态分布上)总是给出相同的值?