#include <iostream>
#include <vector>
#include <string>
#include <random>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{
const auto random_seed = 199712;
std::default_random_engine engine(static_cast<unsigned int>(random_seed)); //定义随机数生成引擎
std::uniform_real_distribution<double> even(-3.0, 3.0);//取值范围
std::vector<double>valueVector(20);
for(std::size_t i=0; i < 20; ++i) {
valueVector[i] = even(engine);//按照上述平均分布生成随机数
}
for (std::size_t j=0; j < valueVector.size(); ++j)
std::cout << valueVector[j]<<endl;
return 0;
}
#include <iostream>
#include <vector>
#include <string>
#include <random>
#include <algorithm>
#include <cmath>
using namespace std;
int main()
{ auto seed = 19917;
std::default_random_engine e(static_cast<unsigned int>(seed)); //定义随机数生成引擎
std::normal_distribution<double> n(4.0, 0.517);//4.0 是均值, 0.517是方差
std::vector<double>valueVector(20);
for(std::size_t i=0; i < 20; ++i) {
valueVector[i] = n(e);//按照上述正态分布生成随机数
}
for (std::size_t j=0; j < valueVector.size(); ++j)
std::cout << valueVector[j]<<endl;
return 0;
}
|