There is uniform_int_distribution in < random > When I creating that I define an interval. Can I change this interval after the creation?
for example
<
Just assign a new distribution to the variable:
std::uniform_int_distribution<int> distr(0, 10);
distr = std::uniform_int_distribution<int>(5, 13);
Or, create a parameter for that (@awesomeyi answer required distribution object creation, this still requires param_type object creation)
std::uniform_int_distribution<int> distr(0, 10);
distr.param(std::uniform_int_distribution<int>::param_type(5, 13));
Proof that param_type will work (for @stefan):
P is the associated param_type. It shall satisfy the CopyConstructible, CopyAssignable, and EqualityComparable requirements. It also has constructors that take the same arguments of the same types as the constructors of D and has member functions identical to the parameter-returning getters of D
http://en.cppreference.com/w/cpp/concept/RandomNumberDistribution
You can through the param()
function.
std::uniform_int_distribution<int> distr(0, 10);
std::uniform_int_distribution<int>::param_type d2(2, 10);
distr.param(d2);