variate_generator クラス
エンジンおよび分布をラップします。
template<class Engine, class Dist>
class variate_generator {
public:
typedef Engine engine_type;
typedef engine-value-type engine_value_type;
typedef Dist distribution_type;
typedef typename Dist::result_type result_type;
variate_generator(engine_type eng0, distribution_type dist0);
result_type operator()();
template<class T>
result_type operator()(T value);
engine_value_type& engine();
const engine_value_type& engine() const;
distribution_type& distribution();
const distribution_type& distribution() const;
result_type min() const;
result_type max() const;
private:
Engine eng; // exposition only
Dist dist; // exposition only
};
パラメーター
Engine
乱数エンジンの型。Dist
分布の型。
解説
このテンプレート クラスは、エンジンおよび分布を保持し、ラップされたエンジン オブジェクトを distribution オブジェクトの operator() に渡すことによって値を生成するオブジェクトを表します。
テンプレート引数 Engine には、Eng、Eng*、Eng& のいずれかの型を指定できます (Eng はエンジン)。型 Eng は基になるエンジンの型です。対応する Eng 型のオブジェクトが、基になるエンジン オブジェクトです。
このテンプレートは、ラップされたエンジンを使って、engine オブジェクトによって生成される値の型と、distribution オブジェクトに必要な値の型とを比較します。ラップされたエンジンの operator() は、Dist::input_type 型の値を返します。この値は、次のように生成されます。
Engine::result_type と Dist::input_type がどちらも整数型である場合、eng() が Dist::input_type 型に変換されて返されます。
Engine::result_type と Dist::input_type がどちらも浮動小数点型である場合、(eng() - eng.min()) / (eng.max() - eng.min()) が Dist::input_type 型に変換されて返されます。
Engine::result_type が整数型で、Dist::input_type が浮動小数点型である場合、(eng() - eng.min()) / (eng.max() - eng.min() + 1) が Dist::input_type 型に変換されて返されます。
Engine::result_type が浮動小数点型で、Dist::input_type が整数型である場合、((eng() - eng.min()) / (eng.max() - eng.min()) * std::numeric_limits<Dist::input_type>::max() が Dist::input_type 型に変換されて返されます。
必要条件
ヘッダー : <random>
名前空間: std
参照
関連項目
variate_generator::distribution
variate_generator::distribution_type
variate_generator::engine_type