random_shuffle produces the same random order each time. Is there any way the seed std::random_shuffle? (srand didn't help).
#include <vector>
#include <algorithm>
#include <iostream.h>
typedef struct {int i;} TESTSTRUCT;
using namespace std;
int main()
{
vector<TESTSTRUCT> vec;
vector<TESTSTRUCT>::iterator it;
TESTSTRUCT t;
for (int n=0; n<10; n++)
{
t.i = n;
vec.push_back(t);
}
std::random_shuffle(vec.begin(), vec.end());
it = vec.begin();
while(it != vec.end())
{
cout << it->i << endl;
it++;
}
return 0;
}
I always get
6
8
9
2
1
4
3
7
0
5
#include <vector>
#include <algorithm>
#include <iostream.h>
typedef struct {int i;} TESTSTRUCT;
using namespace std;
int main()
{
vector<TESTSTRUCT> vec;
vector<TESTSTRUCT>::iterator it;
TESTSTRUCT t;
for (int n=0; n<10; n++)
{
t.i = n;
vec.push_back(t);
}
std::random_shuffle(vec.begin(), vec.end());
it = vec.begin();
while(it != vec.end())
{
cout << it->i << endl;
it++;
}
return 0;
}
I always get
6
8
9
2
1
4
3
7
0
5