- random[meta header]
- std[meta namespace]
- weibull_distribution[meta class]
- function[meta id-type]
- cpp11[meta cpp]
explicit weibull_distribution(RealType a = 1.0, RealType b = 1.0); // (1)
weibull_distribution() : weibull_distribution(1.0) {} // (1) C++20
explicit weibull_distribution(RealType a, RealType b = 1.0); // (2) C++20
explicit weibull_distribution(const param_type& parm); // (3)
- (1) : デフォルトコンストラクタ
- C++17まで : ワイブル分布の形状パラメータ(ワイブル係数)
aと尺度パラメータbを受け取るコンストラクタ。
- C++20 : ワイブル分布の形状パラメータ
a = 1.0、尺度パラメータb = 1.0として(2)に委譲。
- (2) : ワイブル分布の形状パラメータ(ワイブル係数)
aと尺度パラメータbを受け取るコンストラクタ
- (3) : パラメータオブジェクトを受け取るコンストラクタ。
param_typeは、このクラスの(1)のコンストラクタと同じオーバーロードを持ち、それらのコンストラクタのパラメータを保持している。このコンストラクタでは、paramオブジェクトが持っているパラメータを、このクラスのコンストラクタに転送する。
#include <iostream>
#include <random>
int main()
{
std::random_device seed_gen;
std::default_random_engine engine(seed_gen());
// (1) パラメータを個別に指定する
{
// 形状パラメータ1.0、尺度パラメータ1.0で分布させる
std::weibull_distribution<> dist(1.0, 1.0);
for (int i = 0; i < 10; ++i) {
std::cout << dist(engine) << std::endl;
}
}
std::cout << std::endl;
// (2) パラメータを通して範囲指定する
{
using dist_type = std::weibull_distribution<>;
// 形状パラメータ1.0、尺度パラメータ1.0で分布させる
dist_type::param_type param(1.0, 1.0);
dist_type dist(param);
for (int i = 0; i < 10; ++i) {
std::cout << dist(engine) << std::endl;
}
}
}
0.912249
0.0289652
0.0760671
1.46664
0.634032
3.00078
2.21434
1.23163
0.242967
0.942412
0.173383
0.533308
0.806522
0.197259
0.968115
0.388902
0.609052
1.28074
1.33422
0.696135