#include <iostream>

#include <random>

#include <limits>

#include <type_traits>

#include <cfloat>


#define CSTR


using   i32 = int;

using   u32 = unsigned int;

using   f32 = float;


template< typename T >

using   DENSITY = typename std::conditional<

    std::numeric_limits< T >::is_integer,

    std::uniform_int_distribution<>,

    std::uniform_real_distribution<> >::type;  


template< typename T, typename METHOD = std::mt19937 >

class               RNG

{

private:

    METHOD          method; 

    DENSITY< T >    random;


public:

    CSTR            RNG()

    :   random( std::numeric_limits< T >::lowest(),

                    std::numeric_limits< T >::max() )

    {

    }

    CSTR            RNG( u32 range )

    :   random( 0, range -

            ( std::numeric_limits< T >::is_integer? 1 : FLT_EPSILON ) )

    {

    }

    CSTR            RNG( T from, T to )

    :   random( from, to )

    {

    }


    void            set( T from, T to )

    {

        random.param( decltype( random.param() ){ from, to } );

    }

    

    auto            get()

    {

        return  random( method );

    }

};


using   namespace   std;


#define loop( count ) for( int i_ = 0; i_ < count; ++i_ )


int main()

{

    {

        RNG< i32 > rng( 10 );

        loop( 20 )

            cout << rng.get() << " ";

        cout << endl;

    }

    {

        RNG< i32 > rng( 10 );

        loop( 20 )

            cout << rng.get() << " ";

        cout << endl;

    }

    {

        RNG< f32 > rng( 10 );

        loop( 10 )

            cout << rng.get() << " ";

        cout << endl;

    }


    return 0;

}


결과 :

8 1 9 8 1 9 9 2 6 3 0 5 2 1 5 9 9 9 9 9 8 1 9 8 1 9 9 2 6 3 0 5 2 1 5 9 9 9 9 9 1.35477 8.35009 9.68868 2.21034 3.08167 5.47221 1.88382 9.92881 9.96461 9.67695