mardi 21 juin 2016

Getting same number after random in C++ QT

I have function that shuffles my list(vector). Every time when i run again application it returns same result like before. I'm getting same random results. Tried to fix it with qsrand but it won't help. Any suggestion how to fix this problem? I'm using C++ Qt 5.7. Here is shuffle function:

void deck::Shuffle()
{
int j;
card temp;
for (int i = 1; i < GetDeckSize()-2; ++i)
{
    qsrand(QTime::currentTime().msec());
    j =  qrand() % ((cards.size() + 1) - 1) + 1;
    temp = cards[i];
    cards[i] = cards[j];
    cards[j] = temp;
}
}

Thank you in advance.




Aucun commentaire:

Enregistrer un commentaire