variate_generator Class
包裝一個引擎和散發。
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 對應的物件為基礎的物件。
範本使用包裝執行引擎與 distribution 物件所需的值之型別的 engine 物件產生的值的型別。 包裝的引擎的 operator() 傳回型別 Dist::input_type的值,會建立如下所示:
如果傳回 eng()的 Engine::result_type 和 Dist::input_type 都是整數類資料型別,則型別轉換 Dist::input_type。
如果傳回 (eng() - eng.min()) / (eng.max() - eng.min())的 Engine::result_type 和 Dist::input_type 是兩個浮點型別,則型別轉換 Dist::input_type。
如果 Engine::result_type 是整數類資料型別,則會傳回 (eng() - eng.min()) / (eng.max() - eng.min() + 1)的 Dist::input_type 是浮點型別,則型別轉換 Dist::input_type。
如果 Engine::result_type 是浮點型別,則會傳回 ((eng() - eng.min()) / (eng.max() - eng.min()) * std::numeric_limits<Dist::input_type>::max()的 Dist::input_type 是整數類資料型別,則型別轉換 Dist::input_type。
需求
標題: <random>
命名空間: std
請參閱
參考
variate_generator::distribution
variate_generator::distribution_type
variate_generator::engine_type