Randomize using class

I am trying to make a loop and get a diferent number every time from a class.But, I am getting always the same number. What is the problem?

#include <iostream>
#include <cstdlib>
#include<ctime>
using namespace std;

class dic
{
public:

int sort()
{
srand(time(0));
return (rand() % 3)+1;

}
};

int main()
{dic dice;
int points=0;

for (int i=0;i<10;i++)
{
points=dice.sort();
cout<<points;
}
}
Only call srand() ONCE. i.e. put it as the first thing you do in main.
Thanks,

The problem is that I am not able to put srand() in main, this is an exercise where I was told not to change main function, I can only work on the class.
Hmm...then you could try setting a global bool that tells you whether you have set srand() or not, then check that.
I added a new function on the class, that I called void random() , and put the srand() on the function, that solved the problem. Thanks, you gave me some direction on the solution!
Ah, yeah, that would work, and would probably work better.
Topic archived. No new replies allowed.