Skip to content

Instantly share code, notes, and snippets.

@satojkovic
Last active December 18, 2015 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save satojkovic/5855870 to your computer and use it in GitHub Desktop.
Save satojkovic/5855870 to your computer and use it in GitHub Desktop.
#include <vector>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef struct {
string v1;
string v2;
} SAMPLE_DATA;
int myrandom(int i) { return rand()%i; }
int main()
{
vector<SAMPLE_DATA> my_sample;
my_sample.resize(10);
for(int i=0; i < 10; i++) {
stringstream ss;
ss << i;
string s = "str" + ss.str();
my_sample.at(i).v1 = s;
my_sample.at(i).v2 = s;
}
srand(static_cast<unsigned int>(time(NULL)));
random_shuffle(my_sample.begin(), my_sample.end(), myrandom);
for(int i=0; i<10; i++) {
cout << my_sample.at(i).v1 << " , " << my_sample.at(i).v2 << std::endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment