2016-09-21 2 views
0

MersenneTwisterアルゴリズムを実装しているクラスを作成して疑似乱数を生成しました。私の質問は、私のジェネレータをデフォルトのstd :: uniform_int_distributionで動作させるにはどうすればいいですか?それを行う必要がありますUniformRandomBitGeneratorの概念をモデル化uniform_int_distributionで独自の乱数クラスを作成する

class MersenneTwister 
{ 
public: 
    void initialize(unsigned int seed); 
    unsigned int extract(); 

private: 
    unsigned int twist(); 
    unsigned int _x[624]; 
    signed int _index; 
}; 

答えて

6

:私のクラスのヘッダーを以下に示す

http://en.cppreference.com/w/cpp/concept/UniformRandomBitGenerator

Screenshot of the concept's requirements

このような何か:

#include <limits> 

class MersenneTwister 
{ 
public: 
    void initialize(unsigned int seed); 
    unsigned int extract(); 

    // 
    // model the concept here 
    // 

    using result_type = unsigned int; 
    static constexpr result_type min() { return std::numeric_limits<result_type>::min(); } 
    static constexpr result_type max() { return std::numeric_limits<result_type>::max(); } 
    result_type operator()() 
    { 
     return extract(); 
    } 

private: 
    unsigned int twist(); 
    unsigned int _x[624]; 
    signed int _index; 
}; 
関連する問題