Problem with qsrand and time(0)[SOLVED]
At least, there is where I think I'm having a problem.
I have the next code:
Code:
QColor vColor
[11] = {Qt
::black, Qt
::red, Qt
::darkRed, Qt
::darkGreen, Qt
::blue, Qt
::darkBlue, Qt
::darkCyan, Qt
::darkMagenta, Qt
::yellow, Qt
::darkYellow, Qt
::darkGray};
qsrand(time(0));
int iRandomColor = (qrand() % 11);
QColor myColor
= vColor
[iRandomColor
];
This is a part of a function called by the constructor of a class, and I create two objects one after the other. But they always have the same color. BUT if I stop it (breakpoint or "Sleep"), the color is different.
I think this could be because the qsrand is always choosing the same value, because it's executed at the same time (or pretty close), that's why it chooses a different color when I stop the execution.
But I'm not sure... and, anyway, I don't know how I could solve that.
any idea? thanks!
Re: Problem with qsrand and time(0)
try qsrand again before creating another object
Re: Problem with qsrand and time(0)
yes, it was something like that :)
I just seed the time at the beginning of the code, and get the random number later with qrand when necessary.
thanks!