使用Boost高效生成数字

时间:2013-01-08 11:20:43

标签: c++ boost

我希望使用Boost生成超过10 ^ 8个随机数。它们必须正态分布,标准偏差为1,平均值为0.这是我的MWE:

#include <iostream>
#include <vector>

#include <time.h>
#include <boost/random/normal_distribution.hpp>
#include <boost/random/mersenne_twister.hpp>
#include <boost/random/variate_generator.hpp>

using namespace std;

int main()
{
    typedef boost::mt19937                     ENG;
    typedef boost::normal_distribution<double> DIST;
    typedef boost::variate_generator<ENG,DIST> GEN;

    ENG  eng;
    DIST dist(0,1);
    GEN  gen(eng,dist);

    gen.engine().seed(time(0));

    vector<double> nums;

    for(int i=0; i<500; i++)
    {
        nums.push_back(gen());
    }

    return 0;
}

我在这方面有两个问题:

  1. 我使用的方法是否正确引擎?或者我需要在每个号码之前播种吗?
  2. 我的方法有效吗?或者有更好的方法吗?
  3. 编辑请注意,代码中没有瓶颈。我只是想知道从专业的角度来看我的方法是否正确

    我应该说这些数字(所有这些数字)必须通过适当的常数进行缩放。我的计划是为此使用for循环。

    最佳, 奈尔斯。

0 个答案:

没有答案
相关问题