Share via


shuffle_order_engine Class

Generates a random sequence by reordering the values returned from its base 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;
    };

Parameters

  • Engine
    The stored engine type.

  • K
    The K engine parameter.

Remarks

This template class describes a compound engine that produces values by reordering the values returned by its base engine. Each constructor fills the array stored_arr with K values returned by the base engine. It then stores in stored_y an additional value returned by the base engine. Each element of the generated sequence is then obtained from stored_y, after which:

  • The array index J is computed as K * (stored_y - min()) / (max() - min() + 1).

  • stored_y is replaced by stored_arr[J].

  • stored_arr[j] is replaced by stored_eng().

The engine's state is the state of stored_eng, followed by the K elements of stored_arr, followed by stored_y.

The value of the template argument K must be greater than zero.

Requirements

Header: <random>

Namespace: std

See Also

Reference

<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

Other Resources

<random> Members