简体   繁体   English

如何使用 std::uniform_int_distribution<t> ::参数()?</t>

[英]How to use std::uniform_int_distribution<T>::param()?

I would like to be able to reset the lower and upper bounds of a std::uniform_int_distribution<T> object after it has been created, and it seems the param function in the class allows this functionality.我希望能够在创建std::uniform_int_distribution<T> object 后重置它的下限和上限,并且 ZA2F2ED4F8EBDCC4CBB4C21A2 中的param function 似乎允许此功能。 See https://en.cppreference.com/w/cpp/numeric/random/uniform_int_distribution/param (2).请参阅https://en.cppreference.com/w/cpp/numeric/random/uniform_int_distribution/param (2)。

But it's not clear to me how to construct this param_type object that it takes in. Could someone provide an example?但是我不清楚如何构建它所接受的这个param_type object。有人可以提供一个例子吗?

It's not very clear from the documentation, but here it is:从文档中不是很清楚,但这里是:

auto d = std::uniform_int_distribution<int>{1, 10};

d.param(std::uniform_int_distribution<int>::param_type{11, 24});

Here's how you can find this information in the docs:以下是如何在文档中找到此信息的方法:

std::uniform_int_distribution

Member types会员类型

param_type : the type of the parameter set, see RandomNumberDistribution . param_type :参数集的类型,请参见RandomNumberDistribution

RandomNumberDistribution随机数分布

P , the type named by D::param_type , which P ,由D::param_type命名的类型,其中

  • [...] [...]
  • has a constructor taking identical arguments as each of the constructors of D that take arguments corresponding to the distribution parameters.有一个构造函数采用与D的每个构造函数相同的 arguments,该构造函数采用与分布参数对应的 arguments。

So basically std::uniform_int_distribution<int>::param_type has a constructor taking identical arguments as std::uniform_int_distribution<int> .所以基本上std::uniform_int_distribution<int>::param_type有一个构造函数,它采用与std::uniform_int_distribution<int>相同的 arguments 。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM