C++ OOP: how to create a random number generator object?
<p>So this question is sort of one of translation.  I am new to C++, and was looking through the class documentation.  However, it looks like finding the answer to my question is a bit hard via the documentation. </p>

<p>I have code for generating a random number between 0 and 1 in C++: (obtained from <a href="http://en.cppreference.com/w/cpp/numeric/random/uniform_real_distribution" rel="nofollow">here</a>, since the rand() function solution for floats is integer based)</p>

<pre><code>#include &lt;random&gt;
#include &lt;iostream&gt;

int main()
{
    std::random_device rd;
    std::mt19937 gen(rd());
    std::uniform_real_distribution&lt;&gt; dis(0, 1); //corrected from 1,2
    for (int n = 0; n &lt; 10; ++n) {
        std::cout &lt;&lt; dis(gen) &lt;&lt; ' ';
    }
    std::cout &lt;&lt; '\n';
}
</code></pre>

<p>Next, I would like to create a class or struct or something (not really an OOP guy) that has an API like: </p>

<pre><code>float x = my_RandomNumberGenerator.next();
</code></pre>

<p>In python, I might write something like: </p>

<pre><code>class my_RNG():
    def __init__(self):
        self.rd = (the random device object I initialize in c code)
        self.gen = (the mersenne_twister engine object)(rd)
        self.distribution = (the uniform real distribution object)

    def next():
        return self.distribution(self.gen)

my_randomNumberGenerator = my_RNG()
print(my_randomNumberGenerator.next())
</code></pre>

<p>How would I implement this in C++? </p>

<p><strong>update</strong> Here is what I have so far (it does not work... or compile...but there seems to be some strangeness in the way things are initialized in my template code that I got from the reference site that I don't understand): </p>

<pre><code>#include &lt;iostream&gt;
#include &lt;random&gt;


class MyRNG
{
    public:
        float next(void);
    private:
        std::random_device randomDevice;
        std::mt19937_64 randomGenerator;
        std::uniform_real_distribution distribution;
        MyRNG(float range_lower,float range_upper);

};
MyRNG::MyRNG(float range_lower, float range_upper)
{
    randomGenerator = std::mersenne_twister_engine(randomDevice);
    distribution = std::uniform_real_distribution&lt;&gt; distribution(range_lower,range_upper);
}
MyRNG::next(void)
{
    return distribution(randomGenerator);
}

int main() {
    MyRNG my_rng = MyRNG(0,1);
    std::cout &lt;&lt; my_rng.next() &lt;&lt; std::endl;
    return 0;
}
</code></pre>

<p>You can create a class that holds a random number generator as a private member variable (like <code>std::mt19937</code>) and seeds it in the constructor. Your <code>next</code> function could just invoke the stored generator to get the next value (applying whatever distribution you want (if any) of course).</p>

<p>This is not very complicated, so I'm afraid I'm missing the <em>real</em> point of your question..</p>

python c++ oop