shuffle_order_engine クラス

ベースのエンジンから返された値を並べ替えることで、ランダム シーケンスを生成します。

template<class Engine,
    size_t K>
    class shuffle_order_engine {
public:
    typedef Engine base_type;
    typedef typename base_type::result_type result_type;
    static constexpr size_t table_size = K;
    shuffle_order_engine();
    explicit shuffle_order_engine(const base_type& eng);
    explicit shuffle_order_engine(result_type x0);
    explicit shuffle_order_engine(seed_seq& seq);
    void seed();
    void seed(result_type x0);
    void seed(seed_seq& seq);
    const base_type& base() const;
    static constexpr result_type min();
    static constexpr result_type max();
    result_type operator()();
    void discard(unsigned long long count);
private:
    Engine stored_eng;
    result_type stored_arr[K];
    result_type stored_y;
    };

パラメーター

  • Engine
    格納されているエンジンの型。

  • K
    K エンジン パラメーター。

解説

このテンプレート クラスは、ベースとなるエンジンから返された値の一部を並べ替えることによって値を生成する複合エンジンを表します。各コンストラクターは、配列 stored_arr に、ベースとなるエンジンから返された K 値を格納します。次に、stored_y の中に、ベースとなるエンジンから返された他の値を格納します。その後、生成されたシーケンスの各要素が、stored_y から次のように取得されます。

  • 配列インデックス J は、K * (stored_y - min()) / (max() - min() + 1) として計算されます。

  • stored_y は、stored_arr[J] に置き換えられます。

  • stored_arr[j] は、stored_eng() に置き換えられます。

エンジンの状態は、stored_eng の状態を初期状態とし、その後、stored_arr の K 要素、次に stored_y となります。

テンプレート引数 K の値は、0 よりも大きい必要があります。

必要条件

ヘッダー : <random>

名前空間: std

参照

関連項目

<random>

shuffle_order_engine::base

shuffle_order_engine::base_type

shuffle_order_engine::discard

shuffle_order_engine::operator()

shuffle_order_engine::seed

shuffle_order_engine::shuffle_order_engine