Here's a function from my prog:
void CDeck:
eal(void)
{
srand((unsigned)time(0)); //Start random generator
vector <CARD> Cards; //Declare cards vector
for (int i = 1 ; i <= 52 ; i++ )
{
Cards.push_back(i); //Fill Cards with values 1-52
}
//Print original sequence
cout << "Original deck: (" << endl;
for (vector <CARD>::iterator Iter1 = Cards.begin( ) ; Iter1 != Cards.end( ) ; Iter1++ )
cout << *Iter1 << " ";
cout << "
" << endl;
//Shuffle sequence
random_shuffle( Cards.begin(), Cards.end() );
//Works no problem
//Print shuffled sequence
cout << "Cards shuffled. New order: (" << endl;
for (vector <CARD>::iterator Iter2 = Cards.begin( ) ; Iter2 != Cards.end( ) ; Iter2++ )
cout << *Iter2 << " ";
cout << "
" << endl;
//TODO: Hand cards out to players.
}
How do I seed the random_shuffle() so it doesn't rearrange Cards in the same order every run?
I tried using:
//Shuffle sequence
random_shuffle( Cards.begin(), Cards.end(), rand() );
error C2664: 'std::random_shuffle' : cannot convert parameter 3 from 'int' to 'int &'
A reference that is not to 'const' cannot be bound to a non-lvalue
tried:
//Shuffle sequence
int random_num = rand();
random_shuffle( Cards.begin(), Cards.end(), random_num );
error C2064: term does not evaluate to a function taking 1 arguments
It's probabaly some stupid error that i missed...
void CDeck:
{
srand((unsigned)time(0)); //Start random generator
vector <CARD> Cards; //Declare cards vector
for (int i = 1 ; i <= 52 ; i++ )
{
Cards.push_back(i); //Fill Cards with values 1-52
}
//Print original sequence
cout << "Original deck: (" << endl;
for (vector <CARD>::iterator Iter1 = Cards.begin( ) ; Iter1 != Cards.end( ) ; Iter1++ )
cout << *Iter1 << " ";
cout << "
//Shuffle sequence
random_shuffle( Cards.begin(), Cards.end() );
//Works no problem
//Print shuffled sequence
cout << "Cards shuffled. New order: (" << endl;
for (vector <CARD>::iterator Iter2 = Cards.begin( ) ; Iter2 != Cards.end( ) ; Iter2++ )
cout << *Iter2 << " ";
cout << "
//TODO: Hand cards out to players.
}
How do I seed the random_shuffle() so it doesn't rearrange Cards in the same order every run?
I tried using:
//Shuffle sequence
random_shuffle( Cards.begin(), Cards.end(), rand() );
error C2664: 'std::random_shuffle' : cannot convert parameter 3 from 'int' to 'int &'
A reference that is not to 'const' cannot be bound to a non-lvalue
tried:
//Shuffle sequence
int random_num = rand();
random_shuffle( Cards.begin(), Cards.end(), random_num );
error C2064: term does not evaluate to a function taking 1 arguments
It's probabaly some stupid error that i missed...