2

I am writing a class that samples from a specific known probability distribution. Since the quality of random number generators can vary, I want my class to be templated on the user's choice of random engine. I want to use the concept std::uniform_random_bit_generator to do that. So my class will take an object t of type T where T is an std::uniform_random_bit_generator. I then want to sample from my distribution by using the output of invoking t (using calculus).

The problem I am running into is that I don't understand from the definition of std::uniform_random_bit_generator what the output of invoking t is and how I should use that output in the most general way. If I knew, for instance, that t would always return an integer between t::min() and t::max(), then I would be able to finish my class. However, invoking t could return a double or some other type that is non-trivial to work with.

How should I sample from a distribution using an object t of type T that satisfies the general concept std::uniform_random_bit_generator?

mana
  • 545
  • 4
  • 12
  • 2
    So... why don't you just do those things? The [concept requirements](https://en.cppreference.com/w/cpp/numeric/random/uniform_random_bit_generator) spell out pretty explicitly what you need to provide. – Nicol Bolas Aug 23 '20 at 14:06
  • @NicolBolas because I am having difficulty reading the concept requirements. Hence, "What is the ```std::uniform_random_bit_generator``` concept?" It looks like an ```std::uniform_random_bit_generator``` needs to be both invocable and have ```G::min()``` and ```G::max()``` members functions. Does that mean I MUST use a function object? If so, this question probably reduces to "what is a function object and how do I use one?" If not, then what are my options? – mana Aug 23 '20 at 14:21
  • You are correct in your assumtions, thus your question is a duplicate of [this one](https://stackoverflow.com/questions/356950/what-are-c-functors-and-their-uses). – Fureeish Aug 23 '20 at 20:04
  • 1
    While I believe the first version of the question was the best for Stack Overflow, it didn't receive any responses. I have edited the question with my specific problem. – mana Aug 25 '20 at 13:08

0 Answers0