Randomize inside a class

I am having some issues when I try to fill an array with random values inside a class. I have a ten elements array and constructor initalizes them,
calling for function member sort()
MiniVector::MiniVector()
{
vectors=new int[10];
for (int i=0;i<10;i++)
{
vectors[i]=sort();
}


}
int MiniVector::sort()
{
srand(unsigned(time(NULL)));//seed for randomize
srand(time(0));
return rand()%100;
}

The problem is that sort() is filling array with same number. Any ideas?
srand(time(0)) should be called once and only once per program.

On a different subject, I think sort() is a terrible name for a function that returns a random number.
So, where should I put it? I tried on constructor, now I have randomize numbers, but every time I run the program, I get the same randomize numbers(ssed is not working). I cannot put it on main.
Thanks
put srand(time(0)) in your main function and remove all the other calls
I can't put it in the main, is there any other solution using only the class itself?
Add a private static bool in your class and initialize it to false. Then on the constructor if that if false call srand and set it to true

eg:
1
2
3
4
5
6
7
8
class MiniVector
{
    private:
        static bool sr;
    public:
        MiniVector() { if (!sr){ srand(time(0)); sr=true; } /*...*/ }
};
bool MiniVector::sr = false;
Topic archived. No new replies allowed.