如何使用boost weibull分布库生成随机数? 我想用C++中的威布尔分布生成随机数。谁能给我一些提示吗

如何使用boost weibull分布库生成随机数? 我想用C++中的威布尔分布生成随机数。谁能给我一些提示吗,c++,boost,C++,Boost,谢谢我想这可以回答你的问题: 我想这可以回答你的问题: 以下是使用Boost库的解决方案: #include <iostream> using namespace std; #include <boost/random/mersenne_twister.hpp> // For boost::mt19937 #include <boost/random/variate_generator.hpp> #include <boost/rando

谢谢

我想这可以回答你的问题:


我想这可以回答你的问题:


以下是使用Boost库的解决方案:

#include <iostream>
using namespace std;

#include <boost/random/mersenne_twister.hpp>        // For boost::mt19937
#include <boost/random/variate_generator.hpp>
#include <boost/random/weibull_distribution.hpp>

#include <iostream>
using namespace std; 

int main() {
    // Choose precision
    cout.precision(10);
    cout << endl;

    // To get random generated numbers:
    boost::mt19937 rng(12);
    double shape = 3.0;
    double scale = 0.5;
    boost::random::weibull_distribution<> myWeibull2(shape, scale);
    boost::random::variate_generator<boost::mt19937&, boost::random::weibull_distribution<> > rand_Weibull(rng, myWeibull2);

    cout << "Random numbers generated from a Weibull distribution:" << endl;
    double rn;
    for (int i=0; i < 10; ++i)
    {
        rn = rand_Weibull();
        cout << rn << endl;
    }
    cout << endl;

    return 0;
}

以下是使用Boost库的解决方案:

#include <iostream>
using namespace std;

#include <boost/random/mersenne_twister.hpp>        // For boost::mt19937
#include <boost/random/variate_generator.hpp>
#include <boost/random/weibull_distribution.hpp>

#include <iostream>
using namespace std; 

int main() {
    // Choose precision
    cout.precision(10);
    cout << endl;

    // To get random generated numbers:
    boost::mt19937 rng(12);
    double shape = 3.0;
    double scale = 0.5;
    boost::random::weibull_distribution<> myWeibull2(shape, scale);
    boost::random::variate_generator<boost::mt19937&, boost::random::weibull_distribution<> > rand_Weibull(rng, myWeibull2);

    cout << "Random numbers generated from a Weibull distribution:" << endl;
    double rn;
    for (int i=0; i < 10; ++i)
    {
        rn = rand_Weibull();
        cout << rn << endl;
    }
    cout << endl;

    return 0;
}

可能的答案太多,或者好的答案对于这种格式来说太长。请添加详细信息以缩小答案集或隔离可以在几个段落中回答的问题。可能的答案太多,或者好的答案对于此格式来说太长。请添加详细信息,以缩小答案集或隔离可以在几段中回答的问题。
#include <iostream>
using namespace std;

#include <boost/random/mersenne_twister.hpp>        // For boost::mt19937
#include <boost/random/variate_generator.hpp>
#include <boost/random/weibull_distribution.hpp>

#include <iostream>
using namespace std; 

int main() {
    // Choose precision
    cout.precision(10);
    cout << endl;

    // To get random generated numbers:
    boost::mt19937 rng(12);
    double shape = 3.0;
    double scale = 0.5;
    boost::random::weibull_distribution<> myWeibull2(shape, scale);
    boost::random::variate_generator<boost::mt19937&, boost::random::weibull_distribution<> > rand_Weibull(rng, myWeibull2);

    cout << "Random numbers generated from a Weibull distribution:" << endl;
    double rn;
    for (int i=0; i < 10; ++i)
    {
        rn = rand_Weibull();
        cout << rn << endl;
    }
    cout << endl;

    return 0;
}