fiet/RandomNumberGenerator

#include <iostream>

using namespace std;

class RNGInterface
{
public:
        virtual RNGInterface*
        next() = 0;

        virtual int
        draw() = 0;
};


template <int A, int B, int M, int CURRENT>
class LKG :
        public RNGInterface
{
        typedef LKG<A, B, M, (A*CURRENT+B)%M> Next;
public:
        virtual RNGInterface*
        next()
        {
                return new Next;
        }

        virtual int
        draw()
        {
                return CURRENT;
        }
};

// Wrapper
template<int A=211, int B=1663, int M=7875, int CURRENT=1234>
class RNG
{
public:
        RNG() :
                rng(new LKG<A, B, M, CURRENT>())
        {}

        int
        draw()
        {
                RNGInterface* tmp = rng;
                rng = tmp->next();
                delete tmp;
                return rng->draw();
        }

private:
        RNGInterface* rng;
};

int main()
{
        RNG<> rng;
        for (int ii = 0; ii < 30; ++ii)
        {
                cout << rng.draw() << endl;
        }
}