[ create a new paste ] login | about

Link: http://codepad.org/oeGMXWx4    [ raw code | output | fork ]

C++, pasted on Mar 3:
#include<ctime>

class init_random {
public: 
  init_random() { std::cout <<"init" << std::endl; srand(0); }
};

class Random
{
public:
        Random(void);
        ~Random(void);
        int Next(const int maxValue);
        int Next(const int minValue,const int maxValue);
        int Next();
        double NextDouble();
private:
        static init_random _g_rand;
};

init_random Random::_g_rand;

Random::Random(void)
{
}
 
int Random::Next()
{
        return rand();
}
 
int Random::Next(const int maxValue)
{
        int rez=rand()%maxValue;
        return rez;
}
 
int Random::Next(const int minValue, const int maxValue)
{
        if(maxValue>minValue)
        {
                int rez=rand()%(maxValue-minValue)+minValue;
                return rez;
        }
        else
                return 0;
}
 
double Random::NextDouble()
{
        double rez=rand()/(static_cast<double> (RAND_MAX));
        return rez;
}
 
 
Random::~Random(void)
{
}

int main()
{
   Random r;
   std::cout << r.Next();
}


Output:
1
2
init
1804289383


Create a new paste based on this one


Comments: