Tieni presente che la impostazione del 'seed' con srand è una cosa "globale", non ha quindi senso farla nel costruttore della classe.
Io, come base, farei così:
Codice:
#include <cstdlib>
#include <ctime>
class Rnd
{
private:
int min;
int max;
public:
Rnd (int min, int max);
int next ();
static void seed ();
static void seed (unsigned int seed);
};
Rnd::Rnd (int min, int max)
{
this->min = min;
this->max = max;
}
int Rnd::next ()
{
double d = rand () / (RAND_MAX+1.0);
return ((int) (d * (max-min+1))) + min;
}
void Rnd::seed ()
{
srand ((unsigned int) time (NULL));
}
void Rnd::seed (unsigned int seed)
{
srand (seed);
}