创建与C ++ 11随机标头兼容的自定义分发

时间:2016-11-11 18:56:44

标签: c++ c++11 random

<random>库中的自定义分发外,是否可以创建自定义分发?我想做一个像

那样的(在界面中)行为的发行版
std::uniform_int_distribution
std::normal_distribution
...etc

我的意思是我想做类似以下的事情

std::random_device rd;
std::mt19937 gen(rd());

// Is something like the following possible?
my_custom_distribution dist;
dist(gen);

看起来分发必须遵循RandomNumberDistribution概念。是否有可能创建一种与其他公用事业“发挥良好”的新型发行方式,即发电机和发动机?

1 个答案:

答案 0 :(得分:3)

最低要求是:

using result_type = ?;
result_type operator()();
static result_type min();
static result_type max();

其中result_type是一些无符号整数类型。这是&#34; UniformRandomBitGenerator&#34;概念

大多数C ++ <random>发行版也满足&#34; RandomNumberEngine&#34;。

有关详细信息,请参阅cppreference或标准。