1

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. See 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?

Peter O.
  • 32,158
  • 14
  • 82
  • 96
24n8
  • 1,898
  • 1
  • 12
  • 25
  • 1
    Does this answer your question? [Can I change a distribution parameters?](https://stackoverflow.com/questions/31372520/can-i-change-a-distribution-parameters) – Durstann Jul 28 '20 at 03:43

1 Answers1

3

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.

RandomNumberDistribution

P, the type named by D::param_type, which

  • [...]
  • has a constructor taking identical arguments as each of the constructors of D that take arguments corresponding to the distribution parameters.

So basically std::uniform_int_distribution<int>::param_type has a constructor taking identical arguments as std::uniform_int_distribution<int>.

bolov
  • 72,283
  • 15
  • 145
  • 224